Search code examples
redux-toolkitrtk-query

Determine a connection loss/deriving an isConnectionLost state while using RTK Query


There is a notistack example displaying a snack bar when a connection loss occures: https://notistack.com/examples#dismiss-programmatically

My interest is in how to actually determine this while using RTK Query to access endpoints solely on servers under my control. I guess determining a timeout is enough. Is an error already there in error despite not being an http error or can I assume a timeout when both isSuccess and isError are false?

Thank you for your help!


Solution

  • The next version (1.9) of RTK Query will allow you to use a timeout option with fetchBaseQuery and add a {code: 'TIMEOUT_ERROR'} error.

    If you look at the 1.9 integration PR you can already install that from the CodeSandbox CI build.