Open
Description
At the moment fetch
and other similar functions to make network requests doesn't have a in-depth description of errors:
Failed to fetch
To improve this, it would be nice if the message included the status and/or the actual underlying error. The format could look like:
Failed to fetch: 400 Bad Request
It could further be extended to include information about the response, which can be accessed through the thrown error object (e.g. FetchError
):
try {
const response = await fetch("...");
} catch (error) {
if (error.response && error.response.data) {
print('Failed:', error.response.data);
}
}
Use case
My current use case is trying to fetch an image from Thispersondoesnotexist:
const img = await fetchImg("https://thispersondoesnotexist.com/image");
This only seem to fail in Scripter, as both curl and httpie works. But I cannot verify what the error is.