Skip to content

Commit

Permalink
Enforce error.errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Jun 5, 2022
1 parent 23f683b commit 0fbd21a
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/error/normalize/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,11 @@ const normalizeCause = function (error) {
// Also ensure `AggregateError` instance have an `errors` property.
const normalizeAggregate = function (error) {
if (Array.isArray(error.errors)) {
normalizeAggregateErrors(error)
setErrorProperty(error, 'errors', error.errors.map(normalizeError))
} else if (error instanceof AggregateError) {
setErrorProperty(error, 'errors', [])
} else if (error.errors !== undefined) {
// eslint-disable-next-line fp/no-delete
delete error.errors
}
}

const normalizeAggregateErrors = function (error) {
if (error instanceof AggregateError || error.errors.some(isErrorInstance)) {
setErrorProperty(error, 'errors', error.errors.map(normalizeError))
}
}

const isErrorInstance = function (error) {
return error instanceof Error
}

0 comments on commit 0fbd21a

Please sign in to comment.