Merge branch 'json-parse'

This commit is contained in:
Joe Nelson
2014-10-14 19:28:04 -07:00
2 changed files with 10 additions and 1 deletions
+1 -1
View File
@@ -59,7 +59,7 @@ jsonBodyAction req handler = do
parse <- jsonBody req
case parse of
Left err -> return $ responseLBS status400 [jsonContentType] json
where json = JSON.encode . JSON.object $ [("error", JSON.String $ cs err)]
where json = JSON.encode . JSON.object $ [("error", JSON.String $ "Failed to parse JSON payload. " <> cs err) ]
Right body -> handler body
jsonBody :: Request -> IO (Either String SqlRow)
+9
View File
@@ -68,6 +68,15 @@ spec = around appWithFixture $ do
matchHeaders = ["Location" <:> "/compound_pk?k1=eq.12&k2=eq.42"]
}
context "with invalid json payload" $
it "fails with 400 and error" $
post "/simple_pk" "}{ x = 2"
`shouldRespondWith` ResponseMatcher {
matchBody = Just [json| {"error":"Failed to parse JSON payload. Failed reading: satisfy"} |]
, matchStatus = 400
, matchHeaders = []
}
describe "Putting record" $ do
context "to unkonwn uri" $