Print preview of JSON body in case of parse failure
This commit is contained in:
parent
91b75741dd
commit
0025226af6
@ -218,3 +218,4 @@ acceptsJson = (maybe False ((== "application/json") . B8.takeWhile (/= ';'))
|
|||||||
. listToMaybe
|
. listToMaybe
|
||||||
. reqAccept)
|
. reqAccept)
|
||||||
`liftM` getRequest
|
`liftM` getRequest
|
||||||
|
|
||||||
|
|||||||
@ -624,8 +624,13 @@ requireJSONResponse = do
|
|||||||
isJSONContentType
|
isJSONContentType
|
||||||
(failure $ T.pack $ "Expected `Content-Type: application/json` in the headers, got: " ++ show headers)
|
(failure $ T.pack $ "Expected `Content-Type: application/json` in the headers, got: " ++ show headers)
|
||||||
case eitherDecode' body of
|
case eitherDecode' body of
|
||||||
-- TODO: include full body in error message?
|
Left err -> do
|
||||||
Left err -> failure $ T.concat ["Failed to parse JSON response; error: ", T.pack err]
|
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
|
Right v -> return v
|
||||||
|
|
||||||
-- | Outputs the last response body to stderr (So it doesn't get captured by HSpec)
|
-- | Outputs the last response body to stderr (So it doesn't get captured by HSpec)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user