vercel / swr-site

The official website for SWR.
https://swr.vercel.app
Apache License 2.0
481 stars 351 forks source link

Feedback for “Error Handling” #569

Open tbdk opened 6 months ago

tbdk commented 6 months ago

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 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.