Skip to content

Commit

Permalink
Merge pull request #1546 from hasufell/PR/hasufell/issue-1545/monad-fail
Browse files Browse the repository at this point in the history
Add `MonadFail` instance for `Handler` wrt #1545
  • Loading branch information
Gaël Deest committed Feb 28, 2022
2 parents 7ef9730 + 181e51d commit 8fccfcc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions servant-server/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

Package versions follow the [Package Versioning Policy](https://pvp.haskell.org/): in A.B.C, bumps to either A or B represent major versions.

Unreleased
----------

- Add `MonadFail` instance for `Handler` wrt [#1545](https://github.com/haskell-servant/servant/issues/1545)

0.19
----

Expand Down
9 changes: 7 additions & 2 deletions servant-server/src/Servant/Server/Internal/Handler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ import Control.Monad.Base
import Control.Monad.Catch
(MonadCatch, MonadMask, MonadThrow)
import Control.Monad.Error.Class
(MonadError)
(MonadError, throwError)
import Control.Monad.IO.Class
(MonadIO)
import Control.Monad.Trans.Control
(MonadBaseControl (..))
import Control.Monad.Trans.Except
(ExceptT, runExceptT)
import Data.String
(fromString)
import GHC.Generics
(Generic)
import Servant.Server.Internal.ServerError
(ServerError)
(ServerError, errBody, err500)

newtype Handler a = Handler { runHandler' :: ExceptT ServerError IO a }
deriving
Expand All @@ -32,6 +34,9 @@ newtype Handler a = Handler { runHandler' :: ExceptT ServerError IO a }
, MonadThrow, MonadCatch, MonadMask
)

instance MonadFail Handler where
fail str = throwError err500 { errBody = fromString str }

instance MonadBase IO Handler where
liftBase = Handler . liftBase

Expand Down

0 comments on commit 8fccfcc

Please sign in to comment.