Skip to content

Commit

Permalink
Fixes pkgxdev#137; TeaError incompat with swallow
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Nov 7, 2022
1 parent 73379bf commit 38ffdcf
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,13 @@ declare global {

Promise.prototype.swallow = function(gristle: unknown) {
return this.catch((err: unknown) => {
if (err instanceof Error) err = err.message
if (isPlainObject(err) && isString(err.code)) err = err.code
if (isRegExp(gristle) && isString(err)) {
if (err instanceof TeaError) {
err = err.id
} else if (err instanceof Error) {
err = err.message
} else if (isPlainObject(err) && isString(err.code)) {
err = err.code
} else if (isRegExp(gristle) && isString(err)) {
if (!err.match(gristle)) throw err
} else if (err !== gristle) {
throw err
Expand Down

0 comments on commit 38ffdcf

Please sign in to comment.