You can add something like this to your startup code (assuming you haven’t already set up custom error handling, in which case you’d need to modify that code):
def error_handler(err):
if isinstance(err, anvil.server.AppOfflineError):
handle_server_connection_error(err)
else:
raise err
def handle_server_connection_error(err):
Notification("Server connection error. If something is not working as expected, please refresh the page.",
style="warning", timeout=5).show()
print(repr(err))
set_default_error_handling(error_handler)