Nothing spectacular, but I thought I’d share it anyway.
Basically a higher order function that you can wrap arbitrary functions in so offline mode cases are handled on the form side.
Plug your functions to handle in here.
def try_action(self, function_to_try):
try:
function_to_try()
except anvil.server.AppOfflineError:
alert("No network connection. Check your connection and try again later!")
For example here’s an event handler for a click event:
def button_save_to_database_click(self, **event_args):
self.try_action(self.save_to_database)
And the base function it is pointing to:
def save_to_database(self, **event_args):
new_node = self.node_container.get_components()[0]
sample_tree = self.load_data(new_node)
anvil.server.call('upsert_hierarchy', sample_tree)