Skip to content

Commit

Permalink
Add allowErrorTypes()
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed May 29, 2022
1 parent 194b531 commit 724666d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/error/types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { normalizeError } from './utils.js'
import { wrapError } from './wrap.js'

// Ensure an error is among a specific set of error types.
// Otherwise, assign a default error type (`errorTypes[0]`).
export const allowErrorTypes = function (error, errorTypes) {
const errorA = normalizeError(error)
return errorTypes.some((errorType) => errorA instanceof errorType)
? errorA
: wrapError(errorA, '', errorTypes[0])
}

0 comments on commit 724666d

Please sign in to comment.