-
-
Notifications
You must be signed in to change notification settings - Fork 415
309 handle application exceptions with 500 errors #954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 6 commits
ff4e2af
547adab
a90b671
4d46e98
3d9a151
64686f3
5b13ff4
465e0b8
a786dc4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
{-# LANGUAGE UndecidableInstances #-} | ||
module Servant.Server.Internal.RoutingApplication where | ||
|
||
import Control.DeepSeq (force) | ||
import Control.Monad (ap, liftM) | ||
import Control.Monad.Base (MonadBase (..)) | ||
import Control.Monad.Catch (MonadThrow (..)) | ||
|
@@ -84,13 +85,20 @@ instance MonadTransControl RouteResultT where | |
instance MonadThrow m => MonadThrow (RouteResultT m) where | ||
throwM = lift . throwM | ||
|
||
toApplication :: RoutingApplication -> Application | ||
toApplication ra request respond = ra request routingRespond | ||
where | ||
routingRespond :: RouteResult Response -> IO ResponseReceived | ||
routingRespond (Fail err) = respond $ responseServantErr err | ||
routingRespond (FailFatal err) = respond $ responseServantErr err | ||
routingRespond (Route v) = respond v | ||
toApplication :: Bool -> RoutingApplication -> Application | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Last nitpick: let's have data Evaluate = Force | Lazy deriving (Show) so we won't be |
||
toApplication fullyEvaluate ra request respond = | ||
ra request (maybeEval routingRespond) | ||
where | ||
maybeEval :: (RouteResult Response -> IO ResponseReceived) | ||
-> RouteResult Response -> IO ResponseReceived | ||
maybeEval resp = | ||
if fullyEvaluate | ||
then force resp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. http://hackage.haskell.org/package/deepseq-1.4.3.0/docs/src/Control.DeepSeq.html#line-482 - |
||
else resp | ||
routingRespond :: RouteResult Response -> IO ResponseReceived | ||
routingRespond (Fail err) = respond $ responseServantErr err | ||
routingRespond (FailFatal err) = respond $ responseServantErr err | ||
routingRespond (Route v) = respond v | ||
|
||
-- | A 'Delayed' is a representation of a handler with scheduled | ||
-- delayed checks that can trigger errors. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm against of using
Context
to guide whether to eval or not eval. IMHO single global choice should be enough for now.Something #309 (comment) is good.
Context won't work for subapis anyway, as we give only single
Context
toserveWithContext
. And if we use combinators to alter the context, we could be more direct and alter "whether to eval or not".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment suggests both a global setting & a Context. Are you requesting both, or just the global?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just global I think.