How to catch 401 error from Axios? #752
-
Hi all, I'm struggling with how to catch and respond appropriately to a 401 error from an API call using axios. I've switched from using Suspense, as I thought that was getting in the way of those functions, but it doesn't seem to have made any difference. I'm sure I'm missing something obvious, but I can't see the wood for the trees. It occurs to me that SWR should return the error object from axios, which would include the detail I need, but it seems to return a subset of the object instead? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
OK, I discovered that my error boundary was catching the error object from SWR (which was the cached error) and stopping any future call to my fetcher, meaning my error handler was not then called on the next error. |
Beta Was this translation helpful? Give feedback.
OK, I discovered that my error boundary was catching the error object from SWR (which was the cached error) and stopping any future call to my fetcher, meaning my error handler was not then called on the next error.
I've stopped my error boundary from handling the cached error from SWR and it's now working as expected.