swr
swr copied to clipboard
SWR global error handling doesn't catch all error
Bug report
as per doc here, the error handler should catch all error for global error handling purpose https://swr.vercel.app/docs/error-handling
<SWRConfig value={{
onError: (error, key) => {
if (error.status !== 403 && error.status !== 404) {
// We can send the error to Sentry,
// or show a notification UI.
}
}
}}>
<MyApp />
</SWRConfig>
But it doesn't register error from:
- useSWRMutation
- mutate
- useSWRImmutable (I'm not sure about this one yet)
Expected Behavior
it should catch all error for global error handling purpose, especially all async function error / fetchers
Repro Steps / Code Example
- set up useSWRImmutable, useSWRMutation, and throw error inside it
- check if the error is logged by <SWRConfigValue={{ onError }}>
Additional Context
SWR version. Add any other context about the problem here.
workaround for now, catch the error using middleware