-
Notifications
You must be signed in to change notification settings - Fork 602
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
Missing migration path for deprecated responseJSON
and responseText
property
#2923
Comments
This is not what I meant by cloning the response to access the body: const response = await fetch(url, options);
const text = await response.text();
const cloned = response.clone() as OAuth2Response;
try {
const json = JSON.parse(text);
if (response.ok) {
return json;
} else {
cloned.responseJSON = json;
throw cloned;
}
} catch (SyntaxError) {
cloned.responseText = text;
throw cloned;
} I was thinking about something like this: const response = await fetch(url, options);
// Clone before reading, so user can also read this cloned response, without getting error about body being used
const cloned = response.clone() as OAuth2Response;
// Read original response
const text = await response.text();
try {
const json = JSON.parse(text);
if (response.ok) {
return json;
} else {
// We don't need this, the user can just read the cloned response using response.text() or response.json()
// cloned.responseJSON = json;
throw cloned;
}
} catch (SyntaxError) {
// We don't need this, the user can just read the cloned response using response.text() or response.json()
// cloned.responseText = text;
throw cloned;
} This removes the |
Unless I'm not catching onto something, the corrected code is pretty much the same right? I believe that the draft PR does what you're asking for i.e.:
For now I'd like to try to resolve it without making a breaking change, but if it'll be too cumbersome then we might drop them with the next release. |
Your PR is almost correct, you just need to place the |
I also think it's not possible to clone an already read response, see https://developer.mozilla.org/en-US/docs/Web/API/Response/clone#:~:text=clone()-,throws%20a%20TypeError,-if%20the%20response |
During typescript migration we've noted that
responseJSON
andresponseText
properties returned fromOAuth2PasswordGrantAuthenticator
are deprecated. However I've overlooked the fact that there's no clear migration path for this.Originally reported here: #2883 (comment)
Draft: #2922
The text was updated successfully, but these errors were encountered: