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

Check MIME type before parsing responses as JSON #1365

Merged
merged 1 commit into from
Aug 23, 2024

Conversation

axelboc
Copy link
Collaborator

@axelboc axelboc commented Aug 23, 2024

Addresses #1355 (comment)

I was able to write a wretch add-on for this, which is pretty awesome. 🎉 The add-on adds a method called expectJson to wretch's chainable API (more specifically to the response chain, so after get, post, etc.)

So you can now do: .get(...).expectJson().json() and you'll see something like this:

image

You have to go down the stack trace a bit to find the location of the problematic fetch call, but I think that's okay.

@axelboc axelboc marked this pull request as ready for review August 23, 2024 08:10
@elmjag
Copy link
Contributor

elmjag commented Aug 23, 2024

Is it possible to include call do the json parsing inside the expectJson function?

It would be nice if we could just do:

return endpoint.get('/beam/info').expectJson();

@axelboc
Copy link
Collaborator Author

axelboc commented Aug 23, 2024

Even better, thanks 👍

I called it safeJson, though.

@elmjag elmjag self-requested a review August 23, 2024 09:16
@marcus-oscarsson
Copy link
Member

Nice

@marcus-oscarsson
Copy link
Member

Thanks @elmjag and @axelboc

@marcus-oscarsson marcus-oscarsson merged commit 7b31160 into develop Aug 23, 2024
13 checks passed
@marcus-oscarsson marcus-oscarsson deleted the expect-json-addon branch August 23, 2024 09:26
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.

3 participants