Skip to content

How to gracefully handle API that sometimes return html instead of JSON #1223

Answered by iMacTia
mbajur asked this question in Help
Discussion options

You must be logged in to vote

Hi @mbajur, that's a bit strange as the content_type: /\bjson$/ option exists specifically to solve this issue. That option in fact is a pattern match on the Content-Type header that triggers the response parsing if and only if the pattern matches the header (see: https://github.com/lostisland/faraday_middleware/blob/895301d88c5006cdf5b66d33b1c106863a5525bc/lib/faraday_middleware/response_middleware.rb#L37).

By the look of it, it seems as if the server is returning you a Content-Type: application/json header, while the body is in HTML.
That would of course be an issue on the server and would need to be resolved there.

Would it be possible for you to double-check the response headers of th…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@mbajur
Comment options

@iMacTia
Comment options

@mbajur
Comment options

Answer selected by mbajur
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants