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

feat: useBody takes content-type header into account #201

Closed
wants to merge 1 commit into from

Conversation

tobiasdiez
Copy link
Contributor

@tobiasdiez tobiasdiez commented Oct 16, 2022

Improves the body parsing methods in the following ways:

Depends on unjs/destr#10.

@tobiasdiez
Copy link
Contributor Author

I think it would also make sense that readBody actually throws an error if the content type says its json but there are parse errors. Currently, this is hidden and devs don't get the chance to react to this (e.g. return an error). Any idea how to make this happen? A boolean object to destr that disables the validation checks?

@pi0
Copy link
Member

pi0 commented Oct 18, 2022

@tobiasdiez Would you please open a new PR that adds { validateJSON: true } support JSON validation to useBody?

@pi0 pi0 closed this Oct 18, 2022
@tobiasdiez
Copy link
Contributor Author

I can do this, but what should be the semantics of validateJSON?

@pi0
Copy link
Member

pi0 commented Oct 18, 2022

Maybe as you mentioned in this PR, validate both headers and also we can throw an error on failed parsing with readBody(event, { validateJSON: true }) ?

(We can add an option for destr { strict: true } here that throws error instead of silent fallback)

@tobiasdiez
Copy link
Contributor Author

Okay, first step is at unjs/destr#11.

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.

None yet

2 participants