36
rated 0 times
[
41]
[
5]
/ answers: 1 / hits: 15997
/ 8 Years ago, tue, may 17, 2016, 12:00:00
I'm using the Fetch API both in the frontend and on the backend (NodeJS), a problem that I've been facing a lot happens when parsing the response as json.
response.json()
will return a promise so I don't know beforehand what the body of the response is, and when the body is empty the JSON parsing will fail with the error:
SyntaxError: Unexpected end of input
So my question is, how to prevent parsing the response when its empty?
Thanks
More From » node.js