Fix: Uncaught promise error #29

This commit is contained in:
surunzi
2017-06-28 20:26:33 +08:00
parent e578c66f82
commit 7eaf017efd
3 changed files with 23 additions and 1 deletions

View File

@@ -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;
}

View File

@@ -245,7 +245,8 @@ function formatErr(err)
var lines = err.stack.split('\n'),
msg = `${err.message || lines[0]}<br/>`;
lines = lines.filter(val => !regErudaJs.test(val));
lines = lines.filter(val => !regErudaJs.test(val))
.map(val => util.escape(val));
var stack = `<div class="eruda-stack eruda-hidden">${lines.slice(1).join('<br/>')}</div>`;

View File

@@ -18,6 +18,9 @@
<li>
<a href="#" id="plugin">Plugin</a>
</li>
<li>
<a href="#" id="issue29">#29</a>
</li>
</ul>
</nav>
<script>
@@ -56,6 +59,16 @@
};
});
});
addClickEvent('issue29', function ()
{
new Promise(function (resolve, reject)
{
resolve();
}).then(function (res)
{
var a = res.a;
})
});
</script>
<script>boot();</script>
</body>