Skip to content

Commit

Permalink
defaultErrorHandler handles text/plain request.
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenXL committed Jun 13, 2018
1 parent c88c201 commit a63bf16
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions yesod-core/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.6.6

* `defaultErrorHandler` handles text/plain requests [#1522](https://github.com/yesodweb/yesod/pull/1520)

## 1.6.5

* Add `fileSourceByteString` [#1503](https://github.com/yesodweb/yesod/pull/1503)
Expand Down
8 changes: 8 additions & 0 deletions yesod-core/Yesod/Core/Class/Yesod.hs
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ defaultErrorHandler NotFound = selectRep $ do
let path' = TE.decodeUtf8With TEE.lenientDecode $ W.rawPathInfo r
defaultMessageWidget "Not Found" [hamlet|<p>#{path'}|]
provideRep $ return $ object ["message" .= ("Not Found" :: Text)]
provideRep $ return $ ("Not Found" :: Text)

-- For API requests.
-- For a user with a browser,
Expand All @@ -638,13 +639,15 @@ defaultErrorHandler NotAuthenticated = selectRep $ do
let apair u = ["authentication_url" .= rend u]
content = maybe [] apair (authRoute site)
return $ object $ ("message" .= ("Not logged in"::Text)):content
provideRep $ return $ ("Not logged in" :: Text)

defaultErrorHandler (PermissionDenied msg) = selectRep $ do
provideRep $ defaultLayout $ defaultMessageWidget
"Permission Denied"
[hamlet|<p>#{msg}|]
provideRep $
return $ object ["message" .= ("Permission Denied. " <> msg)]
provideRep $ return $ "Permission Denied. " <> msg

defaultErrorHandler (InvalidArgs ia) = selectRep $ do
provideRep $ defaultLayout $ defaultMessageWidget
Expand All @@ -655,18 +658,23 @@ defaultErrorHandler (InvalidArgs ia) = selectRep $ do
<li>#{msg}
|]
provideRep $ return $ object ["message" .= ("Invalid Arguments" :: Text), "errors" .= ia]
provideRep $ return $ ("Invalid Arguments: " <> T.intercalate " " ia)

defaultErrorHandler (InternalError e) = do
$logErrorS "yesod-core" e
selectRep $ do
provideRep $ defaultLayout $ defaultMessageWidget
"Internal Server Error"
[hamlet|<pre>#{e}|]
provideRep $ return $ object ["message" .= ("Internal Server Error" :: Text), "error" .= e]
provideRep $ return $ "Internal Server Error: " <> e

defaultErrorHandler (BadMethod m) = selectRep $ do
provideRep $ defaultLayout $ defaultMessageWidget
"Method Not Supported"
[hamlet|<p>Method <code>#{S8.unpack m}</code> not supported|]
provideRep $ return $ object ["message" .= ("Bad method" :: Text), "method" .= TE.decodeUtf8With TEE.lenientDecode m]
provideRep $ return $ "Bad Method " <> TE.decodeUtf8With TEE.lenientDecode m

asyncHelper :: (url -> [x] -> Text)
-> [Script url]
Expand Down
2 changes: 1 addition & 1 deletion yesod-core/yesod-core.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: yesod-core
version: 1.6.5
version: 1.6.6
license: MIT
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>
Expand Down

0 comments on commit a63bf16

Please sign in to comment.