I’m using dash in a scenario where, on occasion, the internet drops out (for a matter of 5-10 seconds) and a callback may fail.
Is there any way to gracefully catch these callback failures, and inform the user? A typical use case is a button call back doing an action, and the user needs to know if that button action failed, and they can respond accordingly (e.g. a ‘save’ failed, and they need to click save again).
You can do this on the clientside via a javascript listener to the fetch events.
window.fetch = new Proxy(window.fetch, {
apply(fetch, that, args) {
// Forward function call to the original fetch
const result = fetch.apply(that, args);
// Do whatever you want with the resulting Promise
result.then((response) => {
if (args[0] == '/_dash-update-component' && !['2','3'].includes(response.status.toString()[0])) {
console.log(response.status)
}
});
return result;
}
});
This will log to the console any time a status comes through other than 2 or 3 when looking for updates. Just change the console.log to be something where you want to display a notification to the user.
Be it an alert that just shows up like dbc.Alert, etc.