ethanent / phin

Node HTTP client
MIT License
576 stars 33 forks source link

try parse JSON and catch error #48

Closed jumoog closed 4 years ago

jumoog commented 4 years ago

if JSON.parse fails it should return {}

maybe you can do someting like

    try {
      return JSON.parse(data);
    }
    catch (error) {
      return {};
    }
jumoog commented 4 years ago

in my case the server returns not json if the server is overloaded

ethanent commented 4 years ago

I'm not so sure that {} is really reasonable. Maybe null would be more apt, but then still I think that most users would want to know if the parsing failed with a proper error rather than just by receiving null.