Global Callback Error Handler - Alert Message

I have lots of callbacks split out into different python files and I want to use a global callback error handler as defined here. I want to be able to show a generic alert or popup to the user whenever an error happens, but without having to change any of my existing callbacks in any way.

Is it possible to define the global callback error handler function in a separate file and return the alert e.g.

def global_error_handler(err):  
  # do error handling stuff here
  return html.Div([dbc.Alert("An error happened", id="alert-fade", dismissable=True, is_open=True)])

I tried this, but obviously it is expecting the objects defined in the Output of the callback which encountered the exception:

dash._grouping.SchemaTypeValidationError: Schema: 
...
...
...
Expected type: (<class 'tuple'>, <class 'list'>)
Received value of type <class 'dash.html.Div.Div'>:
Div([Alert(children='An error happened', id='alert-fade', dismissable=True, is_open=True)])

How do I override this to display my alert without modifying all of my callbacks?

Hello @eldeirdro,

This hasn’t been released yet, but the next release of Dash will have this. :grin:

1 Like

It’s actually already released :tada:

2 Likes

Did you try using the set_props function to display the alert? Then you can skip the return statement and don’t do anything with the original outputs.

2 Likes

@Tobs is correct.

The callbacks expect a return of the same shape as the output definitions, to avoid this, you can return no output and set whatever props using the set_props option.

1 Like

Thank you all! I have it returning an Alert now and it’s working very well. Really appreciate it!!

2 Likes