Skip to content

Commit

Permalink
Fix: Uncaught promise error #29
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Jun 28, 2017
1 parent e578c66 commit 7eaf017
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/Console/Console.es6
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -70,6 +77,7 @@ export default class Console extends Tool
window.onerror = this._origOnerror;
delete this._origOnerror;
}
window.removeEventListener('unhandledrejection', this._rejectionHandler);

return this;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Console/Log.es6
Original file line number Diff line number Diff line change
Expand Up @@ -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>`;

Expand Down
13 changes: 13 additions & 0 deletions test/manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<li>
<a href="#" id="plugin">Plugin</a>
</li>
<li>
<a href="#" id="issue29">#29</a>
</li>
</ul>
</nav>
<script>
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 7eaf017

Please sign in to comment.