Handling api response errors with react query #1242
-
Hello, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It should be enough. Throwing in an async function will convert the Error to a failed promise. react-query will then give you the result in an error state ( Please note that react-query retries queries per default (3 times, with an exponential backoff). So you will not "immediately" see the error (it takes a couple of seconds in the example). You can customize this in the query options: https://react-query.tanstack.com/docs/guides/query-retries If this is not working for you, it would be good if you could post a codesandbox example that shows what is not working. |
Beta Was this translation helpful? Give feedback.
It should be enough. Throwing in an async function will convert the Error to a failed promise. react-query will then give you the result in an error state (
isError: true
andstate === 'error'
). You can see that in action here: https://codesandbox.io/s/nostalgic-feynman-wrm60Please note that react-query retries queries per default (3 times, with an exponential backoff). So you will not "immediately" see the error (it takes a couple of seconds in the example). You can customize this in the query options: https://react-query.tanstack.com/docs/guides/query-retries
If this is not workin…