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 DeriveGeneric #-}
16 {-# LANGUAGE ConstraintKinds #-}
17 {-# LANGUAGE FlexibleContexts #-}
18 {-# LANGUAGE FlexibleInstances #-}
19 {-# LANGUAGE FunctionalDependencies #-}
20 {-# LANGUAGE OverloadedStrings #-}
21 {-# LANGUAGE MultiParamTypeClasses #-}
22 {-# LANGUAGE NoImplicitPrelude #-}
23 {-# LANGUAGE RankNTypes #-}
24 {-# LANGUAGE TemplateHaskell #-}
25 {-# LANGUAGE TypeFamilies #-}
27 module Gargantext.Database.Query.Table.Node.Error where
29 import Gargantext.Database.Admin.Types.Node (NodeId)
30 import Control.Lens (Prism', (#), (^?))
31 import Control.Monad.Error.Class (MonadError(..))
32 import Gargantext.Prelude hiding (sum, head)
33 import Prelude hiding (null, id, map, sum)
35 ------------------------------------------------------------------------
36 data NodeError = NoListFound
49 instance Show NodeError
51 show NoListFound = "No list found"
52 show NoRootFound = "No Root found"
53 show NoCorpusFound = "No Corpus found"
54 show NoUserFound = "No user found"
56 show MkNode = "Cannot make node"
57 show NegativeId = "Node with negative Id"
58 show UserNoParent = "Should not have parent"
59 show HasParent = "NodeType has parent"
60 show NotImplYet = "Not implemented yet"
61 show ManyParents = "Too many parents"
62 show ManyNodeUsers = "Many userNode/user"
63 show (DoesNotExist n) = "Node does not exist" <> show n
65 class HasNodeError e where
66 _NodeError :: Prism' e NodeError
68 nodeError :: ( MonadError e m
71 nodeError ne = throwError $ _NodeError # ne
73 catchNodeError :: (MonadError e m, HasNodeError e) => m a -> (NodeError -> m a) -> m a
74 catchNodeError f g = catchError f (\e -> maybe (throwError e) g (e ^? _NodeError))