generated from tpl/purs
feat: helper function to throw gitea error as js error
This commit is contained in:
parent
e13d2f3b8e
commit
31171561b2
@ -3,6 +3,9 @@ module Gitea.Error where
|
||||
import Prelude
|
||||
|
||||
import Control.Monad.Error.Class (class MonadThrow, throwError)
|
||||
import Data.Eq.Generic (genericEq)
|
||||
import Data.Generic.Rep (class Generic)
|
||||
import Data.Show.Generic (genericShow)
|
||||
import Effect.Aff.Class (class MonadAff)
|
||||
import HTTP.Response as HTTP
|
||||
import HTTP.Response as HTTP.Rep
|
||||
@ -13,6 +16,10 @@ data Error
|
||||
| ENotFound
|
||||
| EValidation { message :: String, url :: String }
|
||||
|
||||
derive instance Generic Error _
|
||||
instance Eq Error where eq = genericEq
|
||||
instance Show Error where show = genericShow
|
||||
|
||||
guardStatusOk :: forall m. MonadThrow Error m => MonadAff m => HTTP.Response -> m Unit
|
||||
guardStatusOk rep = do
|
||||
status <- HTTP.Rep.status rep
|
||||
|
@ -2,12 +2,13 @@ module Gitea.Trans where
|
||||
|
||||
import Prelude
|
||||
|
||||
import Control.Monad.Error.Class (class MonadError, class MonadThrow, throwError)
|
||||
import Control.Monad.Error.Class (class MonadError, class MonadThrow, liftEither, throwError)
|
||||
import Control.Monad.Except (ExceptT, runExceptT)
|
||||
import Control.Monad.Morph (class MFunctor, class MMonad, embed, hoist)
|
||||
import Control.Monad.Reader (class MonadAsk, class MonadReader, ReaderT(..), ask, runReaderT)
|
||||
import Control.Monad.Rec.Class (class MonadRec)
|
||||
import Control.Monad.Trans.Class (class MonadTrans, lift)
|
||||
import Data.Bifunctor (lmap)
|
||||
import Data.Either (Either)
|
||||
import Data.Newtype (class Newtype, unwrap, wrap)
|
||||
import Effect.Aff.Class (class MonadAff)
|
||||
@ -49,3 +50,8 @@ derive newtype instance Monad m => Bind (GiteaT m)
|
||||
|
||||
runGitea :: forall m a. Config -> GiteaT m a -> m (Either Gitea.Error.Error a)
|
||||
runGitea config m = runExceptT $ runReaderT (unwrap m) config
|
||||
|
||||
runGiteaE :: forall m a. MonadThrow Effect.Exception.Error m => Config -> GiteaT m a -> m a
|
||||
runGiteaE config m = do
|
||||
e <- runGitea config m
|
||||
liftEither $ lmap (Effect.Exception.error <<< show) e
|
||||
|
@ -294,7 +294,7 @@ type RepoSectionGiteaStatsImmutable r =
|
||||
|
||||
type RepoMeta =
|
||||
{ "id" :: RepoId
|
||||
, "owner" :: String
|
||||
, "owner" :: Username
|
||||
, "name" :: RepoName
|
||||
, "full_name" :: String
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user