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

Support for universal error catcher #192

Closed
kibertoad opened this issue Jun 27, 2023 · 3 comments
Closed

Support for universal error catcher #192

kibertoad opened this issue Jun 27, 2023 · 3 comments

Comments

@kibertoad
Copy link

kibertoad commented Jun 27, 2023

Currently it does not seem to be possible to specify one catcher for all errors, which may be preferable in case there is no logic specific to particular errors, but just one way to handle them all - e. g. passthrough to an external system, such as BugSnag or Sentry.

Would be great to have something like

wretch("...")
  .anyError((err) => console.log(err))
  .get()

It is sorta kinda doable via .get().res().catch() now, but this can only be applied per request, so it doesn't work as a system-wide (or a client-wide) hook.

@elbywan
Copy link
Owner

elbywan commented Jun 28, 2023

Hey @kibertoad,

Currently it does not seem to be possible to specify one catcher for all errors,

Thanks for your feedback! This is definitely a missing feature.

I just released v2.6.0 which implements a fallback catcher to handle this use case:

wretch(url)
  .catcher(404, err => redirect("/routes/notfound", err.message))
  .catcher(500, err => flashMessage("internal.server.error"))
  // this fallback will trigger for any error except if already caught by other means (like above for 404s and 505s)
  .catcherFallback(err => {
    log("Uncaught error:", err)
    throw err
  })

I hope this will suit your needs 🤞.

@kibertoad
Copy link
Author

thanks a lot!

@kuphg
Copy link

kuphg commented Sep 2, 2023

Hey @elbywan I've actually quite needed this behaviour but found nothing about it on the README.md, it would be nice if it could be updated. Thanks.

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

No branches or pull requests

3 participants