From 753477518f87860dcc4981762e3799d6ffc44f30 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Thu, 3 Feb 2011 06:57:37 +0200 Subject: [PATCH] Exception instance for ErrorHandler --- Yesod/Handler.hs | 7 ++++--- Yesod/Internal.hs | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Yesod/Handler.hs b/Yesod/Handler.hs index 0490c92b..ac3330ae 100644 --- a/Yesod/Handler.hs +++ b/Yesod/Handler.hs @@ -348,9 +348,10 @@ runHandler :: HasReps c -> YesodApp runHandler handler mrender sroute tomr ma sa = YesodApp $ \eh rr cts initSession -> do - let toErrorHandler = - InternalError - . (show :: Control.Exception.SomeException -> String) + let toErrorHandler e = + case fromException e of + Just x -> x + Nothing -> InternalError $ show e let hd = HandlerData { handlerRequest = rr , handlerSub = sa diff --git a/Yesod/Internal.hs b/Yesod/Internal.hs index f3e6ee30..6d9eb8fc 100644 --- a/Yesod/Internal.hs +++ b/Yesod/Internal.hs @@ -2,6 +2,7 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE DeriveDataTypeable #-} -- | Normal users should never need access to these. module Yesod.Internal ( -- * Error responses @@ -46,6 +47,8 @@ import qualified Data.Text.Lazy as LT import qualified Data.Text.Lazy.Encoding as LT import qualified Network.Wai as W +import Data.Typeable (Typeable) +import Control.Exception (Exception) #if GHC7 #define HAMLET hamlet @@ -61,7 +64,8 @@ data ErrorResponse = | InvalidArgs [String] | PermissionDenied String | BadMethod String - deriving (Show, Eq) + deriving (Show, Eq, Typeable) +instance Exception ErrorResponse ----- header stuff -- | Headers to be added to a 'Result'.