normalize-exception
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -21,2 +21,23 @@ /** | ||
type NormalizedError<ErrorArg, OptionsArg extends Options> = Error & | ||
(ErrorArg extends Error | ||
? { | ||
name: DefinedString<ErrorArg['name'], Error['constructor']['name']> | ||
message: DefinedString<ErrorArg['message'], ''> | ||
stack: DefinedString<ErrorArg['stack'], string> | ||
} | ||
: unknown) & | ||
('cause' extends keyof ErrorArg | ||
? { | ||
cause: ErrorArg['cause'] extends undefined | ||
? undefined | ||
: NormalizedError<ErrorArg['cause'], OptionsArg> | ||
} | ||
: {}) & | ||
('errors' extends keyof ErrorArg | ||
? ErrorArg['errors'] extends any[] | ||
? { errors: NormalizedError<ErrorArg['errors'][number], OptionsArg>[] } | ||
: {} | ||
: {}) | ||
/** | ||
@@ -70,8 +91,2 @@ * Normalize exception/error. | ||
options?: Options, | ||
): Error & | ||
(ErrorArg extends Error | ||
? { | ||
name: DefinedString<ErrorArg['name'], Error['constructor']['name']> | ||
message: DefinedString<ErrorArg['message'], ''> | ||
} | ||
: unknown) | ||
): NormalizedError<ErrorArg, Options> |
@@ -19,3 +19,3 @@ import{setErrorProperty}from"./descriptors.js"; | ||
const getStack=function(message="",name="Error"){ | ||
const StackError=getErrorType(name); | ||
const StackError=getErrorClass(name); | ||
const{stack}=new StackError(message); | ||
@@ -28,3 +28,3 @@ return stack===undefined||stack===""? | ||
const getErrorType=function(name){ | ||
const getErrorClass=function(name){ | ||
@@ -31,0 +31,0 @@ class StackError extends Error{} |
{ | ||
"name": "normalize-exception", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"type": "module", | ||
@@ -33,3 +33,3 @@ "exports": "./build/src/main.js", | ||
"error-reporting", | ||
"error-type", | ||
"error-classes", | ||
"normalization", | ||
@@ -50,3 +50,3 @@ "exceptions" | ||
"devDependencies": { | ||
"@ehmicky/dev-tasks": "^1.0.84", | ||
"@ehmicky/dev-tasks": "^1.0.85", | ||
"test-each": "^5.3.0" | ||
@@ -53,0 +53,0 @@ }, |
@@ -355,5 +355,6 @@ [![Codecov](https://img.shields.io/codecov/c/github/ehmicky/normalize-exception.svg?label=tested&logo=codecov)](https://codecov.io/gh/ehmicky/normalize-exception) | ||
like it's 2022 🔮 | ||
- [`create-error-types`](https://github.com/ehmicky/create-error-types): Create | ||
multiple error types | ||
- [`error-type`](https://github.com/ehmicky/error-type): Create one error type | ||
- [`error-custom-classes`](https://github.com/ehmicky/error-custom-classes): | ||
Create multiple error classes | ||
- [`error-custom-class`](https://github.com/ehmicky/error-custom-class): Create | ||
one error class | ||
- [`error-serializer`](https://github.com/ehmicky/error-serializer): Convert | ||
@@ -363,2 +364,4 @@ errors to/from plain objects | ||
error with its `cause` | ||
- [`set-error-props`](https://github.com/ehmicky/set-error-props): Properly | ||
update an error's properties | ||
- [`error-cause-polyfill`](https://github.com/ehmicky/error-cause-polyfill): | ||
@@ -365,0 +368,0 @@ Polyfill `error.cause` |
35526
440
399