is there a global hook to run when thrown HTTPError ? #411
-
when HTTPError happens, is there a global hook to execute instead of catching on every request? use case:
|
Beta Was this translation helpful? Give feedback.
Answered by
sindresorhus
Dec 21, 2021
Replies: 1 comment 2 replies
-
Global hooks is an anti-pattern. Ky has local hooks where you can add a hook and then use |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
ma101an
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Global hooks is an anti-pattern. Ky has local hooks where you can add a hook and then use
ky.extend()
to create a reusable instance with such hook, which you would put in a separate file an import in various places in your app instead of theky
import. Unfortunately, Ky does not yet have abeforeError
hook. For now, you could just wrap Ky in an app-specific "request" method which you use throughout your app.