Handling AppOfflineError more elegantly?

If my users leave my app running for a while then return and click a button, they will generally get an AppOfflineError.

I have two questions about this:

  1. Is there a way to handle this more elegantly? I would rather show a message I’ve written myself rather than have a red Anvil error in the corner. It also clutters up error logs.

  2. Does an app always go offline when it’s not interacted with the server for a while? Or perhaps when the client hasn’t interacted with the user for a while? Is there an inexpensive way to keep an app online?

Thanks!

You may want to look at Custom error handling

Yes.

Yes. Force an interaction every 15 minutes or so, e.g., via a Timer that calls an empty Server-side function.

1 Like

It’s not always the case that an app gives you an AppOfflineError after a period of inactivity. (I think @p.colbert might be thinking about SessionExpiredError, which will usually happen after about 30 mins of inactivity).

You might find this part of a different thread helpful. (“Connection to server failed” here refers to an AppOfflineError)

The “Connection to server failed” error is a different kettle of fish. This is an error the browser gives us when it can’t connect a websocket, and the websocket is how we do anvil.server.call()s. The most typical cause of this is a user’s internet connection flaking out for a second, although it can also be caused by corporate firewalls that shoot down websocket connections. In the former cases (ie most of the time) you’ll find that if you retry the call a moment later it will usually work, so the recommended approach is a global error handler to turn that temporary connectivity issue into a more pleasant experience for the user.

Thank you both! Very helpful and much appreciated!

Absolutely right! Thanks for the correction.