Skip to content

Commit

Permalink
fix(isErr): DOMException return false
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Oct 9, 2024
1 parent 7ecc203 commit d42d3e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/isErr.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,11 @@
_('objToStr');

exports = function(val) {
return objToStr(val) === '[object Error]';
switch (objToStr(val)) {
case '[object Error]':
case '[object DOMException]':
return true;
default:
return val instanceof Error;
}
};
5 changes: 5 additions & 0 deletions test/isErr.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
const isBrowser = util.isBrowser;

it('true', function() {
expect(isErr(new Error())).to.be.true;
if (isBrowser) {
expect(isErr(new DOMException('test'))).to.be.true;
}
});

it('false', function() {
Expand Down

0 comments on commit d42d3e8

Please sign in to comment.