-
Hello there! I have a JSON API client written using Faraday and from time to time, when something goes wrong internally on the API side, they return 50x error as a HTML error page instead of returning it as JSON. As i have a Is there any elegant way of dealing with such scenario? I could catch the exception outside of the client lib but i would rather stick to Faraday way of returning things, together with For this specific case, i could even live without parsing the responses at all when 50x comes in. Thanks in advance for any ideas. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @mbajur, that's a bit strange as the 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. Would it be possible for you to double-check the response headers of the server when status is 500 and body is HTML? |
Beta Was this translation helpful? Give feedback.
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 theContent-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…