{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE TemplateHaskell #-}
+{-# LANGUAGE MonoLocalBinds #-}
module Gargantext.API.Prelude
( module Gargantext.API.Prelude
import Control.Exception (Exception)
import Control.Lens (Prism', (#))
import Control.Lens.TH (makePrisms)
-import Control.Monad.Error.Class (MonadError(..))
import Control.Monad.Except (ExceptT)
import Control.Monad.Reader (ReaderT)
+import Control.Monad.Error.Class (MonadError(..))
import Crypto.JOSE.Error as Jose
import Data.Aeson.Types
+import qualified Data.Text as Text
import Data.Typeable
import Data.Validity
-import Servant
-import Servant.Job.Async
-import Servant.Job.Core (HasServerError(..), serverError)
-
import Gargantext.API.Admin.Orchestrator.Types
import Gargantext.API.Admin.Types
-import Gargantext.API.Ngrams.Types
+import Gargantext.Core.NodeStory
+import Gargantext.Core.Mail.Types (HasMail)
import Gargantext.Core.Types
import Gargantext.Database.Prelude
import Gargantext.Database.Query.Table.Node.Error (NodeError(..), HasNodeError(..))
import Gargantext.Database.Query.Tree
import Gargantext.Prelude
+import qualified Gargantext.Utils.Jobs.Monad as Jobs
+import Servant
+import Servant.Job.Async
+import Servant.Job.Core (HasServerError(..), serverError)
class HasJoseError e where
_JoseError :: Prism' e Jose.Error
joseError :: (MonadError e m, HasJoseError e) => Jose.Error -> m a
joseError = throwError . (_JoseError #)
+type HasJobEnv' env = HasJobEnv env JobLog JobLog
+
type EnvC env =
( HasConnectionPool env
- , HasRepo env -- TODO rename HasNgramsRepo
, HasSettings env -- TODO rename HasDbSettings
, HasJobEnv env JobLog JobLog
, HasConfig env
+ , HasNodeStoryEnv env
+ , HasMail env
)
type ErrC err =
, HasTreeError err
, HasServerError err
, HasJoseError err
- , ToJSON err -- TODO this is arguable
+-- , ToJSON err -- TODO this is arguable
, Exception err
)
type GargServerC env err m =
- ( CmdRandom env err m
- , EnvC env
- , ErrC err
+ ( CmdRandom env err m
+ , HasNodeStory env err m
+ , EnvC env
+ , ErrC err
+ , ToJSON err
)
type GargServerT env err m api = GargServerC env err m => ServerT api m
type GargNoServer' env err m =
( CmdM env err m
- , HasRepo env
+ , HasNodeStory env err m
, HasSettings env
, HasNodeError err
)
-------------------------------------------------------------------
-
data GargError
= GargNodeError NodeError
| GargTreeError TreeError
| GargInvalidError Validation
| GargJoseError Jose.Error
| GargServerError ServerError
+ | GargJobError Jobs.JobError
deriving (Show, Typeable)
makePrisms ''GargError
instance ToJSON GargError where
- toJSON _ = String "SomeGargErrorPleaseReport"
+ toJSON err = object [("error", String $ Text.pack $ show err)]
instance Exception GargError
instance HasJoseError GargError where
_JoseError = _GargJoseError
-
------------------------------------------------------------------------
-- | Utils
-- | Simulate logs