-
-
Notifications
You must be signed in to change notification settings - Fork 715
Description
This would solve...
Unidici throws an error with the message "Body is unusable" when the body of a response is non-null and the stream is either locked or disturbed. In most cases, this situation occurs because someone has attempted to ready the body twice, such as:
const response = await fetch(url);
console.log(await response.text());
const body = await response.json(); // throws "Body is unusable"The message "Body is unusable" is opaque and requires searching to understand what it means and what the problem is. A more descriptive message would save developers a lot of time.
The implementation should look like...
Changing the string on this line:
Line 411 in fe44b9b
| throw new TypeError('Body is unusable') |
Suggestion: "Body is unusable: Body is either null or the stream has already been read."
The spec only specifies that a TypeError must be thrown, but it does not specify the text contained within that error, so it seems like changing the message would still be in-line with the spec.
I have also considered...
Not filing this issue. 😄