From 7eaf017efdd683efa52287eacf1f1b3da8677f11 Mon Sep 17 00:00:00 2001 From: surunzi Date: Wed, 28 Jun 2017 20:26:33 +0800 Subject: [PATCH] Fix: Uncaught promise error #29 --- src/Console/Console.es6 | 8 ++++++++ src/Console/Log.es6 | 3 ++- test/manual.html | 13 +++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Console/Console.es6 b/src/Console/Console.es6 index 4565845..3363d77 100644 --- a/src/Console/Console.es6 +++ b/src/Console/Console.es6 @@ -15,8 +15,14 @@ export default class Console extends Tool super.init($el); this._appendTpl(); + this._initLogger(); this._exposeLogger(); + this._rejectionHandler = e => + { + this._logger.error(e.reason); + }; + this._initCfg(parent); this._bindEvent(parent); } @@ -60,6 +66,7 @@ export default class Console extends Tool this._origOnerror = window.onerror; window.onerror = (errMsg, url, lineNum, column, errObj) => this._logger.error(errObj ? errObj : errMsg); + window.addEventListener('unhandledrejection', this._rejectionHandler); return this; } @@ -70,6 +77,7 @@ export default class Console extends Tool window.onerror = this._origOnerror; delete this._origOnerror; } + window.removeEventListener('unhandledrejection', this._rejectionHandler); return this; } diff --git a/src/Console/Log.es6 b/src/Console/Log.es6 index 32f3938..8899f73 100644 --- a/src/Console/Log.es6 +++ b/src/Console/Log.es6 @@ -245,7 +245,8 @@ function formatErr(err) var lines = err.stack.split('\n'), msg = `${err.message || lines[0]}
`; - lines = lines.filter(val => !regErudaJs.test(val)); + lines = lines.filter(val => !regErudaJs.test(val)) + .map(val => util.escape(val)); var stack = `
${lines.slice(1).join('
')}
`; diff --git a/test/manual.html b/test/manual.html index e67b579..adc2e67 100644 --- a/test/manual.html +++ b/test/manual.html @@ -18,6 +18,9 @@
  • Plugin
  • +
  • + #29 +