Hey there,
As part of our custom support offering, we just helped a customer set their app with Rollbar, an error-reporting service that deliver you a smartphone notification whenever something goes wrong with your app. With their permission, we’re sharing how we did it with the rest of the community:
First step: Write a function to use the Rollbar API to submit a message. (You might want to put it in a Module so you can use it from lots of different places):
def send_rollbar_message(msg, level='error'):
payload = {
'access_token': 'YOUR-ROLLBAR-CLIENT-TOKEN-GOES-HERE',
'data': {
'environment': 'production',
'platform': 'browser',
'body': {
'level': level,
'message': {
'body': msg
}
}
}
}
anvil.http.request('https://api.rollbar.com/api/1/item/', method='POST', json=True, data=payload)
Second step: Set a default error handler that calls this function to report errors:
def handle_error(err):
# Oops! Hit Rollbar, tell them something bad happened
send_rollbar_message(str(err))
# And now show the red box again
raise err
anvil.set_default_error_handling(handle_error)
That’s it! Now, any uncaught errors in your Anvil forms will be reported via Rollbar, so you can check the App Logs, find what went wrong, and fix it right away. And if you want to pass a non-fatal message, you can call send_rollbar_message('some string', level='message')
.
Do you want this kind of hands-on help with your Anvil development? Contact support@anvil.works to enquire about a support agreement – we’d be happy to help.