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 handling by including response as the cause #29

Closed
BigBlueHat opened this issue Mar 16, 2023 · 2 comments
Closed

Improve error handling by including response as the cause #29

BigBlueHat opened this issue Mar 16, 2023 · 2 comments

Comments

@BigBlueHat
Copy link

First, thank you for building eleventy-fetch! It has been great for the GET + cache pattern that's so common in static site building.

However, dealing with error responses continues to be painful since eleventy-fetch only returns a prose message:

throw new Error(`Bad response for ${this.displayUrl} (${response.status}): ${response.statusText}`)

Could that line be changed to the following?

throw new Error(`Bad response for ${this.displayUrl} (${response.status}): ${response.statusText}`, { cause: response })

That would then provide the whole failed response object for further processing. It would help write much more defensive code when 429's, 401's, etc. are found while collecting data.

Thanks!
🎩

@zachleat
Copy link
Member

oooh I did merge #21 for this but cause looks fancier!

@zachleat
Copy link
Member

I would note that cause is a Node 16.9+ thing and will only be available in those versions. This package will continue to support Node 14+ in v4.0.0

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause

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

No branches or pull requests

2 participants