diff options
| author | Eugen Wissner <belka@caraus.de> | 2020-07-17 07:05:03 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2020-07-17 07:05:03 +0200 |
| commit | 09135c581aaae471f7d964bc2a3a141bef299097 (patch) | |
| tree | bf26b907a13e5f358f91e4c2d7ef661e74fa6805 /src/Language/GraphQL/Error.hs | |
| parent | e24386402be444e643d7d9c8ef82c1fe2205c7fc (diff) | |
| download | graphql-09135c581aaae471f7d964bc2a3a141bef299097.tar.gz | |
Constrain base monad to MonadCatch
Let's try MonadThrow/MonadCatch. It looks nice at a first glance. The
monad transformer stack contains only the ReaderT, less lifts are
required. Exception subtyping is easier, the user can (and should)
define custom error types and throw them. And it is still possible to
use pure error handling, if someone doesn't like runtime exceptions or
need to run a query in a pure environment.
Fixes #42.
Diffstat (limited to 'src/Language/GraphQL/Error.hs')
| -rw-r--r-- | src/Language/GraphQL/Error.hs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/Language/GraphQL/Error.hs b/src/Language/GraphQL/Error.hs index 474ddc7..9df69de 100644 --- a/src/Language/GraphQL/Error.hs +++ b/src/Language/GraphQL/Error.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DuplicateRecordFields #-} +{-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} @@ -8,6 +9,7 @@ module Language.GraphQL.Error , CollectErrsT , Error(..) , Resolution(..) + , ResolverException(..) , Response(..) , ResponseEventStream , addErr @@ -17,6 +19,7 @@ module Language.GraphQL.Error ) where import Conduit +import Control.Exception (Exception(..)) import Control.Monad.Trans.State (StateT, modify, runStateT) import Data.HashMap.Strict (HashMap) import Data.Sequence (Seq(..), (|>)) @@ -102,6 +105,15 @@ data Response a = Response -- Stream. type ResponseEventStream m a = ConduitT () (Response a) m () +-- | Only exceptions that inherit from 'ResolverException' a cought by the +-- executor. +data ResolverException = forall e. Exception e => ResolverException e + +instance Show ResolverException where + show (ResolverException e) = show e + +instance Exception ResolverException + -- | Runs the given query computation, but collects the errors into an error -- list, which is then sent back with the data. runCollectErrs :: (Monad m, Serialize a) |
