Skip to content

Best practices for handling server offline (i.e. Network Error) #1476

Answered by kitten
rsdickerson asked this question in Q&A
Discussion options

You must be logged in to vote

I'd combine some logic to detect offline states, an example of which you can find in the source itself: https://github.com/FormidableLabs/urql/blob/65e15c568c9a0755894dfb02995f0262e1fe75f9/exchanges/graphcache/src/offlineExchange.ts#L59
With the errorExchange which can notify you of any error.

This should allow you to detect temporary offline states and notify the user of them. Alternatively, a lot of web apps also just use the window online/offline events.

While these events aren't as accurate (and will in your case not fire) they often can be used to switch an app into the "offline" state without requiring a request first. The disadvantage of only relying on these though is that they ma…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@rsdickerson
Comment options

@kitten
Comment options

@rsdickerson
Comment options

Answer selected by rsdickerson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants