-
-
Notifications
You must be signed in to change notification settings - Fork 647
Promise.on.error
David Fahlander edited this page Jun 13, 2016
·
7 revisions
Global exception handler for non-catched promises.
Since Dexie 1.0.4
Dexie.Promise.on("error", myGlobalErrorHandler);
function myGlobalErrorHandler(error) {
console.error(error);
return false; // Returning false will prevent the default handler from being called.
}
Dexie.Promise.on("error").unsubscribe(myGlobalErrorHandler);
error: Any | Any uncatched error no matter if it was a DB operation or any other non-db operation. |
This event will fire whenever a Dexie.Promise instance was rejected bug never catched. Returning false from your handler will prevent any earlier registered handler from being called. By default there is a handler that logs each unhandled promise to the console with console.warn()
. Your handler will execute before the default handler. If you want to silence the default handler, return false from your handler.
Dexie.Promise.on("error", function (e) {
var errorLabel = document.getElementByIf('errorLabel');
if (errorLabel) {
errorLabel.innerText = e.stack || e;
return false;
}
});
new Dexie.Promise(function () {
throw "Oops!";
});
// promise not catched, so the error will bubble to Dexie.Promise.on('error').
Dexie.js - minimalistic and bullet proof indexedDB library