react-native-ssl-pinning icon indicating copy to clipboard operation
react-native-ssl-pinning copied to clipboard

Error handling empty responses in `.json()`

Open BerniWittmann opened this issue 3 years ago • 0 comments

When the response body is empty aka response.bodyString === '' then calling response.json() does cause an Unexpected end of json error, since apparently this function cannot handle this edge case.

Reproduction:

  1. Simple Endpoint that returns some json body -> everything works
  2. Simple endpoint that returns nothing (not even an empty json object {} -> Unexpected end of json` error

a simple workaround for now is response.bodyString.length > 0 ? await response.json() : {}, but that should not be the intended use. I suggest doing a check at the beginning of this json function

BerniWittmann avatar Mar 02 '21 07:03 BerniWittmann