Optional
handler: (error: Error) => undefined | booleanA function that accepts the Error
object.
false
to prevent adding an error message to the DOM.true
or undefined
(or throw) to allow the error messages to be added to the DOM.setErrorHandler(error => {
console.warn('Aberdeen render error:', error.message);
// Log to error reporting service
// myErrorReporter.log(error);
try {
// Attempt to show a custom message in the UI
$('div.error-message:Oops, something went wrong!');
} catch (e) {
// Ignore errors during error handling itself
}
return false; // Suppress default console log and DOM error message
});
// Styling for our custom error message
insertCss({
'.error-message': {
backgroundColor: '#e31f00',
display: 'inline-block',
color: 'white',
borderRadius: '3px',
padding: '2px 4px',
}
}, true); // global style
// Cause an error within a render scope.
$('div.box', () => {
// Will cause our error handler to insert an error message within the box
noSuchFunction();
})
Sets a custom error handler function for errors that occur asynchronously within reactive scopes (e.g., during updates triggered by proxy changes in observe or $ render functions).
The default handler logs the error to
console.error
and adds a simple 'Error' message div to the DOM at the location where the error occurred (if possible).Your handler can provide custom logging, UI feedback, or suppress the default error message.