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 Gargantext.Database.Admin.Types.Node (NodeId)
23 import Control.Lens (Prism', (#), (^?))
24 import Control.Monad.Error.Class (MonadError(..))
25 import Gargantext.Prelude hiding (sum, head)
26 import Prelude hiding (null, id, map, sum)
28 ------------------------------------------------------------------------
29 data NodeError = NoListFound
42 instance Show NodeError
44 show NoListFound = "No list found"
45 show NoRootFound = "No Root found"
46 show NoCorpusFound = "No Corpus found"
47 show NoUserFound = "No user found"
49 show MkNode = "Cannot make node"
50 show NegativeId = "Node with negative Id"
51 show UserNoParent = "Should not have parent"
52 show HasParent = "NodeType has parent"
53 show NotImplYet = "Not implemented yet"
54 show ManyParents = "Too many parents"
55 show ManyNodeUsers = "Many userNode/user"
56 show (DoesNotExist n) = "Node does not exist" <> show n
58 class HasNodeError e where
59 _NodeError :: Prism' e NodeError
61 nodeError :: ( MonadError e m
64 nodeError ne = throwError $ _NodeError # ne
66 catchNodeError :: (MonadError e m, HasNodeError e) => m a -> (NodeError -> m a) -> m a
67 catchNodeError f g = catchError f (\e -> maybe (throwError e) g (e ^? _NodeError))