-
-
Notifications
You must be signed in to change notification settings - Fork 460
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
chore(core): try to parse a text/plain content-type response as json #3430
chore(core): try to parse a text/plain content-type response as json #3430
Conversation
🦋 Changeset detectedLatest commit: 9410b43 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
const text = await response.text(); | ||
if (text.startsWith('{')) { | ||
try { | ||
results = JSON.parse(text); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My generator foo is lacking here, does this count, because yield JSON.parse()
seems invalid
21d3735
to
b3cfd44
Compare
throw new Error(await response.text()); | ||
const text = await response.text(); | ||
try { | ||
results = JSON.parse(text); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small issue here, results
is expected to be an async iterator (for the for-await loop below). It's likely not warning here since the result of the parse is any
and it may still appear to work, but that likely will run into a runtime error 🤔
b3cfd44
to
9410b43
Compare
Summary
As seen in #3429, some servers send back the response as
text/plain
which can still be valid JSON.