[REF] component: move error handling into the fiber

This commit is contained in:
Géry Debongnie
2019-10-26 10:27:56 +02:00
committed by Aaron Bohy
parent 2aa705f5c8
commit 2c563ee380
2 changed files with 34 additions and 40 deletions
+28 -1
View File
@@ -195,5 +195,32 @@ export class Fiber {
});
}
handleError(e: Error) {}
/**
* This is the global error handler for errors occurring in Owl main lifecycle
* methods. Caught errors are triggered on the QWeb instance, and are
* potentially given to some parent component which implements `catchError`.
*
* If there are no such component, we destroy everything. This is better than
* being in a corrupted state.
*/
handleError(error: Error) {
let canCatch = false;
let component = this.component;
let qweb = component.env.qweb;
let root = component;
while (component && !(canCatch = !!component.catchError)) {
root = component;
component = component.__owl__.parent!;
}
console.error(error);
qweb.trigger("error", error);
if (canCatch) {
setTimeout(() => {
component.catchError!(error);
});
} else {
root.destroy();
}
}
}