Skip to content

Improve error messages for failed requests #6

Open
@fnky

Description

@fnky

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions