diff --git a/yesod-core/src/Yesod/Core/Json.hs b/yesod-core/src/Yesod/Core/Json.hs index 3ced0c56..5fe75ccf 100644 --- a/yesod-core/src/Yesod/Core/Json.hs +++ b/yesod-core/src/Yesod/Core/Json.hs @@ -218,3 +218,4 @@ acceptsJson = (maybe False ((== "application/json") . B8.takeWhile (/= ';')) . listToMaybe . reqAccept) `liftM` getRequest + diff --git a/yesod-test/Yesod/Test.hs b/yesod-test/Yesod/Test.hs index cb2d9fb2..1bd999e8 100644 --- a/yesod-test/Yesod/Test.hs +++ b/yesod-test/Yesod/Test.hs @@ -624,8 +624,13 @@ requireJSONResponse = do isJSONContentType (failure $ T.pack $ "Expected `Content-Type: application/json` in the headers, got: " ++ show headers) case eitherDecode' body of - -- TODO: include full body in error message? - Left err -> failure $ T.concat ["Failed to parse JSON response; error: ", T.pack err] + Left err -> do + let characterLimit = 1024 + textBody = TL.toStrict $ decodeUtf8 body + bodyPreview = if T.length textBody < characterLimit + then textBody + else T.take characterLimit textBody <> "... (use `printBody` to see complete response body)" + failure $ T.concat ["Failed to parse JSON response; error: ", T.pack err, "JSON: ", bodyPreview] Right v -> return v -- | Outputs the last response body to stderr (So it doesn't get captured by HSpec)