yesod-core 1.2.6.5 → 1.2.6.6
raw patch · 3 files changed
+41/−3 lines, 3 files
Files
Yesod/Core/Internal/Run.hs view
@@ -10,7 +10,8 @@ import Yesod.Core.Internal.Response import Blaze.ByteString.Builder (toByteString) import Control.Applicative ((<$>))-import Control.Exception (fromException, bracketOnError)+import Control.Exception (fromException, bracketOnError, evaluate)+import qualified Control.Exception as E import Control.Exception.Lifted (catch) import Control.Monad.IO.Class (MonadIO) import Control.Monad.IO.Class (liftIO)@@ -94,7 +95,9 @@ YRWai _ -> return yar let sendFile' ct fp p = return $ YRPlain H.status200 (appEndo headers []) ct (ContentFile fp p) finalSession- case contents of+ contents1 <- evaluate contents `E.catch` \e -> return+ (HCError $! InternalError $! T.pack $! show (e :: E.SomeException))+ case contents1 of HCContent status (TypedContent ct c) -> do ec' <- liftIO $ evaluateContent c case ec' of
test/YesodCoreTest/ErrorHandling.hs view
@@ -24,6 +24,11 @@ /error-in-body ErrorInBodyR GET /error-in-body-noeval ErrorInBodyNoEvalR GET /override-status OverrideStatusR GET++-- https://github.com/yesodweb/yesod/issues/658+/builder BuilderR GET+/file-bad-len FileBadLenR GET+/file-bad-name FileBadNameR GET |] overrideStatus = mkStatus 15 "OVERRIDE"@@ -74,6 +79,15 @@ getOverrideStatusR :: Handler () getOverrideStatusR = invalidArgs ["OVERRIDE"] +getBuilderR :: Handler TypedContent+getBuilderR = return $ TypedContent "ignored" $ ContentBuilder (error "builder-3.14159") Nothing++getFileBadLenR :: Handler TypedContent+getFileBadLenR = return $ TypedContent "ignored" $ ContentFile "yesod-core.cabal" (error "filebadlen")++getFileBadNameR :: Handler TypedContent+getFileBadNameR = return $ TypedContent "ignored" $ ContentFile (error "filebadname") Nothing+ errorHandlingTest :: Spec errorHandlingTest = describe "Test.ErrorHandling" $ do it "says not found" caseNotFound@@ -82,6 +96,9 @@ it "error in body == 500" caseErrorInBody it "error in body, no eval == 200" caseErrorInBodyNoEval it "can override status code" caseOverrideStatus+ it "builder" caseBuilder+ it "file with bad len" caseFileBadLen+ it "file with bad name" caseFileBadName runner :: Session () -> IO () runner f = toWaiApp App >>= runSession f@@ -140,3 +157,21 @@ caseOverrideStatus = runner $ do res <- request defaultRequest { pathInfo = ["override-status"] } assertStatus 15 res++caseBuilder :: IO ()+caseBuilder = runner $ do+ res <- request defaultRequest { pathInfo = ["builder"] }+ assertStatus 500 res+ assertBodyContains "builder-3.14159" res++caseFileBadLen :: IO ()+caseFileBadLen = runner $ do+ res <- request defaultRequest { pathInfo = ["file-bad-len"] }+ assertStatus 500 res+ assertBodyContains "filebadlen" res++caseFileBadName :: IO ()+caseFileBadName = runner $ do+ res <- request defaultRequest { pathInfo = ["file-bad-name"] }+ assertStatus 500 res+ assertBodyContains "filebadname" res
yesod-core.cabal view
@@ -1,5 +1,5 @@ name: yesod-core-version: 1.2.6.5+version: 1.2.6.6 license: MIT license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>