Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@block65/custom-error

Package Overview
Dependencies
Maintainers
2
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@block65/custom-error - npm Package Compare versions

Comparing version
12.1.0
to
12.2.0
+2
-2
dist/lib/custom-error.js

@@ -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,

{
"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",