@block65/custom-error
Advanced tools
@@ -143,3 +143,3 @@ export var Status; | ||
| ...(this.cause instanceof Error && { | ||
| cause: CustomError.isCustomError(this.cause) | ||
| cause: 'toJSON' in this.cause && typeof this.cause.toJSON === 'function' | ||
| ? this.cause.toJSON() | ||
@@ -161,3 +161,3 @@ : { | ||
| static fromJSON(params) { | ||
| const { code = Status.UNKNOWN, message, details = [], ...rest } = params; | ||
| const { code = Status.UNKNOWN, message, details = [] } = params; | ||
| const err = new CustomError(message || (Status[params.code] || params.code || 'Error').toString()).debug({ params }); | ||
@@ -164,0 +164,0 @@ err.code = code; |
@@ -7,5 +7,5 @@ import { CustomError } from './custom-error.js'; | ||
| stack?: string; | ||
| cause?: SerializedError[]; | ||
| cause?: SerializedError[] | unknown; | ||
| [key: string]: unknown; | ||
| } | ||
| export declare function serializeError(err: unknown | Error | CustomError): SerializedError; |
| import { serializeError as serialize } from 'serialize-error'; | ||
| import { CustomError } from './custom-error.js'; | ||
| function flattenPreviousErrors(err, accum = []) { | ||
| if (CustomError.isCustomError(err)) { | ||
| const { cause, ...rest } = err; | ||
| return flattenPreviousErrors(cause, [...accum, rest]); | ||
| } | ||
| if (err instanceof Error) { | ||
| if ('cause' in err && err.cause) { | ||
| return flattenPreviousErrors(err.cause, [...accum, err]); | ||
| } | ||
| return [...accum, err]; | ||
@@ -15,3 +14,5 @@ } | ||
| if (CustomError.isCustomError(err)) { | ||
| const previousErrors = 'cause' in err && err.cause ? flattenPreviousErrors(err.cause) : []; | ||
| const previousErrors = 'cause' in err && err.cause | ||
| ? flattenPreviousErrors(err.cause) | ||
| : undefined; | ||
| return { | ||
@@ -22,4 +23,4 @@ ...serialize(err), | ||
| status: err.status, | ||
| cause: previousErrors.map(serializeError), | ||
| ...('debug' in err ? { debug: err.debug() } : {}), | ||
| ...(previousErrors && { cause: previousErrors.map(serializeError) }), | ||
| ...('debug' in err && { debug: err.debug() }), | ||
| }; | ||
@@ -30,3 +31,3 @@ } | ||
| return { | ||
| message: message || '', | ||
| message: message || 'Error', | ||
| name: name || 'Error', | ||
@@ -33,0 +34,0 @@ code, |
+2
-1
| { | ||
| "name": "@block65/custom-error", | ||
| "version": "12.1.0", | ||
| "version": "12.2.0", | ||
| "private": false, | ||
@@ -33,2 +33,3 @@ "license": "UNLICENSED", | ||
| "jest": "^29.7.0", | ||
| "@jest/globals": "^29.7.0", | ||
| "prettier": "^3.2.5", | ||
@@ -35,0 +36,0 @@ "rimraf": "^5.0.5", |
Explicitly Unlicensed Item
LicenseSomething was found which is explicitly marked as unlicensed.
Found 1 instance in 1 package
Unidentified License
LicenseSomething that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
Explicitly Unlicensed Item
LicenseSomething was found which is explicitly marked as unlicensed.
Found 1 instance in 1 package
Unidentified License
LicenseSomething that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
13306
0.7%382
0.26%16
6.67%