create-error-types
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -13,7 +13,7 @@ import normalizeException from"normalize-exception"; | ||
export const callErrorHandler=function( | ||
{ErrorTypes,InternalError,bugsUrl}, | ||
{CustomErrorTypes,InternalError,bugsUrl}, | ||
error) | ||
{ | ||
const errorA=normalizeException(error); | ||
return isKnownError(errorA,ErrorTypes)? | ||
return isKnownError(errorA,CustomErrorTypes)? | ||
errorA: | ||
@@ -23,4 +23,4 @@ new InternalError(getInternalErrorMessage(bugsUrl),{cause:errorA}); | ||
const isKnownError=function(error,ErrorTypes){ | ||
return Object.values(ErrorTypes).includes(error.constructor); | ||
const isKnownError=function(error,CustomErrorTypes){ | ||
return Object.values(CustomErrorTypes).includes(error.constructor); | ||
}; | ||
@@ -27,0 +27,0 @@ |
@@ -1,8 +0,2 @@ | ||
import { | ||
ErrorName, | ||
OnCreate, | ||
ErrorInstance, | ||
ErrorConstructor, | ||
ErrorParams, | ||
} from 'error-type' | ||
import { ErrorName, OnCreate, CustomError, ErrorParams } from 'error-type' | ||
@@ -24,3 +18,3 @@ /** | ||
/** | ||
* Called on any `new ErrorType('message', parameters)`. | ||
* Called on any `new CustomErrorType('message', parameters)`. | ||
* Can be used to customize error parameters or to set error type properties. | ||
@@ -61,3 +55,3 @@ * By default, any `parameters` are set as error properties. | ||
> = { | ||
[errorName in ErrorNames]: ErrorConstructor<errorName, ErrorParamsArg> | ||
[errorName in ErrorNames]: typeof CustomError<errorName, ErrorParamsArg> | ||
} & { | ||
@@ -87,5 +81,5 @@ /** | ||
error: unknown, | ||
) => ErrorInstance<ErrorNames> | ||
) => CustomError<ErrorNames> | ||
export type { ErrorName, ErrorInstance, ErrorConstructor, ErrorParams } | ||
export type { ErrorName, CustomError, ErrorParams } | ||
@@ -92,0 +86,0 @@ /** |
import{callErrorHandler}from"./handler.js"; | ||
import{getOpts}from"./opts.js"; | ||
import{getErrorTypes,createInternalError}from"./types.js"; | ||
import{getCustomErrorTypes,createInternalError}from"./types.js"; | ||
@@ -9,11 +9,11 @@ | ||
const{onCreate,bugsUrl}=getOpts(errorNames,opts); | ||
const ErrorTypes=getErrorTypes(errorNames,onCreate); | ||
const CustomErrorTypes=getCustomErrorTypes(errorNames,onCreate); | ||
const InternalError=createInternalError(); | ||
const errorHandler=callErrorHandler.bind(undefined,{ | ||
ErrorTypes, | ||
CustomErrorTypes, | ||
InternalError, | ||
bugsUrl}); | ||
return{...ErrorTypes,errorHandler}; | ||
return{...CustomErrorTypes,errorHandler}; | ||
} | ||
//# sourceMappingURL=main.js.map |
@@ -41,3 +41,3 @@ import errorType from"error-type"; | ||
export const getErrorTypes=function(errorNames,onCreate){ | ||
export const getCustomErrorTypes=function(errorNames,onCreate){ | ||
return Object.fromEntries( | ||
@@ -44,0 +44,0 @@ errorNames.map((errorName)=>[errorName,errorType(errorName,onCreate)])); |
{ | ||
"name": "create-error-types", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"type": "module", | ||
@@ -49,3 +49,3 @@ "exports": "./build/src/main.js", | ||
"dependencies": { | ||
"error-type": "^2.0.0", | ||
"error-type": "^2.0.1", | ||
"is-plain-obj": "^4.1.0", | ||
@@ -52,0 +52,0 @@ "normalize-exception": "^1.8.0" |
@@ -11,3 +11,3 @@ [![Codecov](https://img.shields.io/codecov/c/github/ehmicky/create-error-types.svg?label=tested&logo=codecov)](https://codecov.io/gh/ehmicky/create-error-types) | ||
- Create [custom error types](#create-error-types-and-handler) | ||
- Create [custom error types](#create-custom-error-types) | ||
- Automatically separate (unhandled) [internal errors](#internal-errors) from | ||
@@ -83,3 +83,3 @@ (handled) user errors | ||
_Type_: `ErrorType` | ||
_Type_: `CustomErrorType` | ||
@@ -106,4 +106,5 @@ Any error name passed as argument is returned as an error type. | ||
Called on any [`new ErrorType('message', parameters)`](#set-error-properties). | ||
Can be used to [customize error parameters](#customize-error-parameters) or set | ||
Called on any | ||
[`new CustomErrorType('message', parameters)`](#set-error-properties). Can be | ||
used to [customize error parameters](#customize-error-parameters) or set | ||
[error type properties](#error-type-properties). By default, any `parameters` | ||
@@ -110,0 +111,0 @@ are [set as error properties](#set-error-properties). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28129
357
187
Updatederror-type@^2.0.1