-
-
Notifications
You must be signed in to change notification settings - Fork 466
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
Uncaught error when body is undefined
in request init
#1666
Comments
Hello! I can't reproduce the bug with the information provided, could you please create a repository where we can test it or let me know if there is another detail when doing the reproduction? |
Perhaps it is related to Bun, Astro, or Vite in some way. I'm not 100% sure where the Request global is being set, but I had assumed it was the browser's. Unfortunately I can't figure out how to install Bun on StackBlitz to dig further into a repro. Regardless, there's clearly some incompatibility in the vast JS/TS ecosystem as a result of overwriting For example: const nativeRequest = new Request()
class CustomRequest extends Request {
constructor(input, init) {
super(input, init);
// add custom parameters
for (const key in init) {
if (!(key in nativeRequest)) {
this[key] = init[key];
}
}
}
} Or class CustomRequest extends Request {
constructor(input, init) {
super(input, init);
// add custom parameters
for (const key in init) {
if (!(key in this)) {
this[key] = init[key];
}
}
}
} |
Since |
I will take a look on this and if its necessary I will make a PR to fix it |
Oh wow, I'm so sorry. I have a repro: https://stackblitz.com/edit/vitejs-vite-3tdy1b?file=src%2FApp.tsx If |
undefined
in request init
Alr makes sense https://github.com/drwpow/openapi-typescript/blob/main/packages/openapi-fetch/src/index.js#L17 return a false positive, you could do the PR fixing this by changing that conditional to |
) * fix: only add custom properties that aren't in the request object Closes #1666 * add changeset
Description
https://github.com/drwpow/openapi-typescript/blob/main/packages/openapi-fetch/src/index.js#L16-L20
Basically,
body
is a getter on theRequest
object and the linked code is trying to write to it. One work around could be to wrap it in a try/catch. Otherwise I think you'll have to ignore some properties in the request initReproduction
Add a
body
to the request init object inopenapi-fetch@0.9.6
e.g.client.POST('/', {body:undefined})
.Happens in all major browsers AFAICT
Checklist
The text was updated successfully, but these errors were encountered: