{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE Arrows #-}
-{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE ConstraintKinds #-}
-{-# LANGUAGE FlexibleContexts #-}
-{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
-{-# LANGUAGE OverloadedStrings #-}
-{-# LANGUAGE MultiParamTypeClasses #-}
-{-# LANGUAGE NoImplicitPrelude #-}
-{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module Gargantext.Database.Query.Table.Node.Error where
+import Data.Text (Text)
+import Gargantext.Database.Admin.Types.Node (NodeId)
import Control.Lens (Prism', (#), (^?))
import Control.Monad.Error.Class (MonadError(..))
import Gargantext.Prelude hiding (sum, head)
| NegativeId
| NotImplYet
| ManyNodeUsers
+ | DoesNotExist NodeId
+ | NeedsConfiguration
+ | NodeError Text
instance Show NodeError
where
show NotImplYet = "Not implemented yet"
show ManyParents = "Too many parents"
show ManyNodeUsers = "Many userNode/user"
+ show (DoesNotExist n) = "Node does not exist" <> show n
+ show NeedsConfiguration = "Needs configuration"
+ show (NodeError e) = "NodeError: " <> cs e
class HasNodeError e where
_NodeError :: Prism' e NodeError
+errorWith :: ( MonadError e m
+ , HasNodeError e)
+ => Text -> m a
+errorWith x = nodeError (NodeError x)
+
nodeError :: ( MonadError e m
, HasNodeError e)
=> NodeError -> m a