Skip to content

Capture JSON parsing errors in Promise #112

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

Merged
merged 2 commits into from
Feb 19, 2020
Merged

Conversation

sunsean
Copy link
Contributor

@sunsean sunsean commented Mar 26, 2019

Currently invalid JSON in the response throws immediately instead of asynchronously.

Copy link

@iiroj iiroj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were also hit by this problem, and the change here certainly fixes it:

// Promise.resolve(JSON.parse(undefined)).then(() => console.log('success')).catch(() => console.log('fail')) 
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
// Promise.resolve(undefined).then(JSON.parse).then(() => console.log('success')).catch(() => console.log('fail'))  
fail

Copy link

@pladaria pladaria left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Owner

@developit developit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So sorry for sleeping on this PR!

@developit developit merged commit ce5f373 into developit:master Feb 19, 2020
developit added a commit to kalisjoshua/unfetch that referenced this pull request Feb 19, 2020
@developit
Copy link
Owner

Released in 4.2.0. Sorry for the super long wait!

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

Successfully merging this pull request may close these issues.

4 participants