Skip to content

Commit

Permalink
Add bugsUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Jun 5, 2022
1 parent 75bb72f commit 782a9cf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
12 changes: 10 additions & 2 deletions src/error/modern/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ import mergeErrorCause from 'merge-error-cause'
// Error handler that normalizes an error, merge its `error.cause` and ensure
// its type is among an allowed list of types.
// Otherwise, assign a default SystemError type.
export const onErrorHandler = function (ErrorTypes, SystemError, error) {
export const onErrorHandler = function (
{ ErrorTypes, SystemError, bugsUrl },
error,
) {
const errorA = mergeErrorCause(error)

if (ErrorTypes.some((ErrorType) => errorA instanceof ErrorType)) {
return errorA
}

const systemError = new SystemError('', { cause: errorA })
const systemErrorMessage = getSystemErrorMessage(bugsUrl)
const systemError = new SystemError(systemErrorMessage, { cause: errorA })
return mergeErrorCause(systemError)
}

const getSystemErrorMessage = function (bugsUrl) {
return bugsUrl === undefined ? '' : `Please report this bug at: ${bugsUrl}`
}
10 changes: 5 additions & 5 deletions src/error/modern/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import {
// - Any browsers: `stacktrace.js`
export const modernErrors = function (errorNames, opts) {
validateErrorNames(errorNames)
const { onCreate } = getOpts(opts)
const { onCreate, bugsUrl } = getOpts(opts)
const SystemError = createSystemError()
const ErrorTypes = createErrorTypes(errorNames, onCreate)
const onError = onErrorHandler.bind(
undefined,
Object.values(ErrorTypes),
const onError = onErrorHandler.bind(undefined, {
ErrorTypes: Object.values(ErrorTypes),
SystemError,
)
bugsUrl,
})
return { ...ErrorTypes, onError }
}

0 comments on commit 782a9cf

Please sign in to comment.