-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1772 from SupercedeTech/make-exception-catching-c…
…onfigurable Make catching exceptions configurable.
- Loading branch information
Showing
7 changed files
with
158 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{-# LANGUAGE TypeFamilies, QuasiQuotes, TemplateHaskell, MultiParamTypeClasses, OverloadedStrings #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE ViewPatterns #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE DeriveAnyClass #-} | ||
|
||
-- | a custom app that throws an exception | ||
module YesodCoreTest.ErrorHandling.CustomApp | ||
(CustomApp(..) | ||
, MyException(..) | ||
|
||
-- * unused | ||
, Widget | ||
, resourcesCustomApp | ||
) where | ||
|
||
|
||
import Yesod.Core.Types | ||
import Yesod.Core | ||
import qualified UnliftIO.Exception as E | ||
|
||
data CustomApp = CustomApp | ||
|
||
mkYesod "CustomApp" [parseRoutes| | ||
/throw-custom-exception CustomHomeR GET | ||
|] | ||
|
||
getCustomHomeR :: Handler Html | ||
getCustomHomeR = | ||
E.throwIO MkMyException | ||
|
||
data MyException = MkMyException | ||
deriving (Show, E.Exception) | ||
|
||
instance Yesod CustomApp where | ||
-- something we couldn't do before, rethrow custom exceptions | ||
catchHandlerExceptions _ action handler = | ||
action `E.catch` \exception -> do | ||
case E.fromException exception of | ||
Just MkMyException -> E.throwIO MkMyException | ||
Nothing -> handler exception |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters