Use displayException

This commit is contained in:
Gregor Kleen 2021-06-30 15:53:11 +02:00
parent cb75192e0c
commit a59f63e033
2 changed files with 5 additions and 5 deletions

View File

@ -17,7 +17,7 @@ import Yesod.Core.Content
import Yesod.Core.Types
import qualified Network.HTTP.Types as H
import qualified Data.Text as T
import Control.Exception (SomeException, handle)
import Control.Exception (SomeException, handle, displayException)
import Data.ByteString.Builder (lazyByteString, toLazyByteString)
import qualified Data.ByteString.Lazy as L
import qualified Data.Map as Map
@ -101,7 +101,7 @@ evaluateContent (ContentBuilder b mlen) = handle f $ do
len `seq` return (Right $ ContentBuilder (lazyByteString lbs) mlen')
where
f :: SomeException -> IO (Either ErrorResponse Content)
f = return . Left . InternalError . T.pack . show
f = return . Left . InternalError . T.pack . displayException
evaluateContent c = return (Right c)
getStatus :: ErrorResponse -> H.Status

View File

@ -47,11 +47,11 @@ toErrorHandler e0 = handleAny errFromShow $
Just (HCError x) -> evaluate $!! x
_ -> errFromShow e0
-- | Generate an @ErrorResponse@ based on the shown version of the exception
-- | Generate an @ErrorResponse@ based on the displayed version of the exception
errFromShow :: SomeException -> IO ErrorResponse
errFromShow x = do
text <- evaluate (T.pack $ show x) `catchAny` \_ ->
return (T.pack "Yesod.Core.Internal.Run.errFromShow: show of an exception threw an exception")
text <- evaluate (T.pack $ displayException x) `catchAny` \_ ->
return (T.pack "Yesod.Core.Internal.Run.errFromShow: display of an exception threw an exception")
return $ InternalError text
-- | Do a basic run of a handler, getting some contents and the final