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 module Gargantext.Database.Query.Table.Node.Error where
13 import Data.Text (Text)
14 import Gargantext.Database.Admin.Types.Node (NodeId)
15 import Control.Lens (Prism', (#), (^?))
16 import Control.Monad.Error.Class (MonadError(..))
17 import Gargantext.Prelude hiding (sum, head)
18 import Prelude hiding (null, id, map, sum)
20 ------------------------------------------------------------------------
21 data NodeError = NoListFound
36 instance Show NodeError
38 show NoListFound = "No list found"
39 show NoRootFound = "No Root found"
40 show NoCorpusFound = "No Corpus found"
41 show NoUserFound = "No user found"
43 show MkNode = "Cannot make node"
44 show NegativeId = "Node with negative Id"
45 show UserNoParent = "Should not have parent"
46 show HasParent = "NodeType has parent"
47 show NotImplYet = "Not implemented yet"
48 show ManyParents = "Too many parents"
49 show ManyNodeUsers = "Many userNode/user"
50 show (DoesNotExist n) = "Node does not exist" <> show n
51 show NeedsConfiguration = "Needs configuration"
52 show (NodeError e) = "NodeError: " <> cs e
54 class HasNodeError e where
55 _NodeError :: Prism' e NodeError
57 errorWith :: ( MonadError e m
60 errorWith x = nodeError (NodeError x)
62 nodeError :: ( MonadError e m
65 nodeError ne = throwError $ _NodeError # ne
67 catchNodeError :: (MonadError e m, HasNodeError e) => m a -> (NodeError -> m a) -> m a
68 catchNodeError f g = catchError f (\e -> maybe (throwError e) g (e ^? _NodeError))