Skip to content

Capture JSON parsing errors in Promise#112

Merged
developit merged 2 commits into
developit:masterfrom
sunsean:patch-1
Feb 19, 2020
Merged

Capture JSON parsing errors in Promise#112
developit merged 2 commits into
developit:masterfrom
sunsean:patch-1

Conversation

@sunsean

@sunsean sunsean commented Mar 26, 2019

Copy link
Copy Markdown
Contributor

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

@iiroj iiroj left a comment

Copy link
Copy Markdown

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

@pladaria pladaria left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

lgtm

@developit developit left a comment

Copy link
Copy Markdown
Owner

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
Copy Markdown
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