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

chore(core): try to parse a text/plain content-type response as json #3430

Merged

Conversation

JoviDeCroock
Copy link
Collaborator

@JoviDeCroock JoviDeCroock commented Nov 12, 2023

Summary

As seen in #3429, some servers send back the response as text/plain which can still be valid JSON.

Copy link

changeset-bot bot commented Nov 12, 2023

🦋 Changeset detected

Latest commit: 9410b43

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@urql/core Minor

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

@JoviDeCroock JoviDeCroock marked this pull request as draft November 12, 2023 13:29
@JoviDeCroock JoviDeCroock marked this pull request as ready for review November 13, 2023 14:58
@JoviDeCroock JoviDeCroock changed the title chore(core): try to parse a no content-type response as json chore(core): try to parse a text/plain content-type response as json Nov 13, 2023
const text = await response.text();
if (text.startsWith('{')) {
try {
results = JSON.parse(text);
Copy link
Collaborator Author

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

throw new Error(await response.text());
const text = await response.text();
try {
results = JSON.parse(text);
Copy link
Member

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 🤔

@kitten kitten merged commit 94e0c31 into urql-graphql:main Nov 14, 2023
13 checks passed
@github-actions github-actions bot mentioned this pull request Nov 13, 2023
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.

2 participants