Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try parse JSON and catch error #48

Closed
jumoog opened this issue Mar 18, 2020 · 2 comments
Closed

try parse JSON and catch error #48

jumoog opened this issue Mar 18, 2020 · 2 comments

Comments

@jumoog
Copy link

jumoog commented Mar 18, 2020

if JSON.parse fails it should return {}

maybe you can do someting like

    try {
      return JSON.parse(data);
    }
    catch (error) {
      return {};
    }
@jumoog
Copy link
Author

jumoog commented Mar 18, 2020

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

@ethanent
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants