From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/web/static/src/js/promise_extension.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 addons/web/static/src/js/promise_extension.js (limited to 'addons/web/static/src/js/promise_extension.js') diff --git a/addons/web/static/src/js/promise_extension.js b/addons/web/static/src/js/promise_extension.js new file mode 100644 index 00000000..4758975c --- /dev/null +++ b/addons/web/static/src/js/promise_extension.js @@ -0,0 +1,22 @@ +/** + * This file adds a 'guardedCatch' function to the Promise API. This function + * has to be used when we don't want to swallow real errors (crashes), like + * 'catch' does (i.e. basically all the time in Odoo). We only execute the + * 'onRejected' handler if the rejection's reason is not an Error, and we always + * return a rejected Promise to let the rejection bubble up (and trigger the + * 'unhandledrejection' event). + */ + +(function () { + var _catch = Promise.prototype.catch; + Promise.prototype.guardedCatch = function (onRejected) { + return _catch.call(this, function (reason) { + if (!reason || !(reason instanceof Error)) { + if (onRejected) { + onRejected.call(this, reason); + } + } + return Promise.reject(reason); + }); + }; +})(); -- cgit v1.2.3