Unexpected token < in JSON at position 0
oh2th opened this issue · 2 comments
Every now and then an API returns garbage instead of the expected JSON.
Could the parseJSON first verify that it actually is parseable instead of getting a SyntaxError from JSON.parse()?
SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse ()
at parseJSON (/app/node_modules/http.min/index.js:106:24)
at IncomingMessage. (/app/node_modules/http.min/index.js:60:22)
at IncomingMessage.emit (node:events:529:35)
at IncomingMessage.emit (node:domain:489:12)
Can you provide an example?
Invalid JSON is covered by this test.
Lines 264 to 273 in bb29b81
I am not fond of checking response content. We could check content-type header.
Found what the issue is, the upstream API returns HTML page while there was Backend server error. Adding now check for result.response.statusCode. So it should be fine. Just so surprised that the API fails so often, and that is not in my hands.
This case can be closed.