Skip to content
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

Improve error messages for failed requests #6

Open
fnky opened this issue Jun 24, 2020 · 2 comments
Open

Improve error messages for failed requests #6

fnky opened this issue Jun 24, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@fnky
Copy link

fnky commented Jun 24, 2020

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.

@fnky fnky changed the title Improve error messages for failed requests. Improve error messages for failed requests Jun 24, 2020
@rsms rsms added the enhancement New feature or request label Jul 7, 2020
@rsms
Copy link
Owner

rsms commented Jul 7, 2020

Good idea with improved error reporting.

Note that https://thispersondoesnotexist.com/image likely fails in Scripter as Scripter runs in a secure web environment where CORS play a part in what resources can and can not be loaded. cURL is not a web tool and thus does not, or does not have to, obey by CORS rules. It's very likely that the website you're talking to does not permit requests from other "origins". You could try ask their support or maintainers.

@fnky
Copy link
Author

fnky commented Jul 7, 2020

Thanks for the info! I think I'll have to use a proxy to fetch it instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants