2 Module : Gargantext.Database.Types.Error
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
11 {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
12 {-# OPTIONS_GHC -fno-warn-orphans #-}
14 {-# LANGUAGE Arrows #-}
15 {-# LANGUAGE ConstraintKinds #-}
16 {-# LANGUAGE FunctionalDependencies #-}
17 {-# LANGUAGE TemplateHaskell #-}
18 {-# LANGUAGE TypeFamilies #-}
20 module Gargantext.Database.Query.Table.Node.Error where
22 import Data.Text (Text)
23 import Gargantext.Database.Admin.Types.Node (NodeId)
24 import Control.Lens (Prism', (#), (^?))
25 import Control.Monad.Error.Class (MonadError(..))
26 import Gargantext.Prelude hiding (sum, head)
27 import Prelude hiding (null, id, map, sum)
29 ------------------------------------------------------------------------
30 data NodeError = NoListFound
45 instance Show NodeError
47 show NoListFound = "No list found"
48 show NoRootFound = "No Root found"
49 show NoCorpusFound = "No Corpus found"
50 show NoUserFound = "No user found"
52 show MkNode = "Cannot make node"
53 show NegativeId = "Node with negative Id"
54 show UserNoParent = "Should not have parent"
55 show HasParent = "NodeType has parent"
56 show NotImplYet = "Not implemented yet"
57 show ManyParents = "Too many parents"
58 show ManyNodeUsers = "Many userNode/user"
59 show (DoesNotExist n) = "Node does not exist" <> show n
60 show NeedsConfiguration = "Needs configuration"
61 show (NodeError e) = "NodeError: " <> cs e
63 class HasNodeError e where
64 _NodeError :: Prism' e NodeError
66 msg :: ( MonadError e m
69 msg x = nodeError (NodeError x)
71 nodeError :: ( MonadError e m
74 nodeError ne = throwError $ _NodeError # ne
76 catchNodeError :: (MonadError e m, HasNodeError e) => m a -> (NodeError -> m a) -> m a
77 catchNodeError f g = catchError f (\e -> maybe (throwError e) g (e ^? _NodeError))