This page leaves the reader with the impression that when working with const { data/trigger, error } = useSWR[Mutation], that SWR will catch any errors thrown inside the fetcher, prevent them from propagating further up by not (re-)throwing and set the error variable with the error caught. However, it is only if the option throwOnError: false has been set, that it will actually not (re-)throw.
I think that this should be made clear in the example (modified example):
const { data, error } = useSWR('/api/user', fetcher, { throwOnError: false}) and that a point should be made of it - also showing an example for why we may not want to set the option. But being very explicit about that option.
https://swr.vercel.app/docs/error-handling#status-code-and-error-object
This page leaves the reader with the impression that when working with
const { data/trigger, error } = useSWR[Mutation]
, that SWR will catch any errors thrown inside the fetcher, prevent them from propagating further up by not (re-)throwing and set theerror
variable with the error caught. However, it is only if the optionthrowOnError: false
has been set, that it will actually not (re-)throw.I think that this should be made clear in the example (modified example):
const { data, error } = useSWR('/api/user', fetcher, { throwOnError: false})
and that a point should be made of it - also showing an example for why we may not want to set the option. But being very explicit about that option.