@block65/custom-error
Advanced tools
@@ -67,3 +67,3 @@ declare type DebugData = Record<string, unknown>; | ||
| */ | ||
| readonly cause?: Error | CustomError; | ||
| readonly cause?: Error | CustomError | unknown; | ||
| /** | ||
@@ -99,7 +99,2 @@ * Further error details suitable for end user consumption | ||
| /** | ||
| * An automatically determined HTTP status code | ||
| * @return {number} | ||
| */ | ||
| get httpStatusCode(): number; | ||
| /** | ||
| * Human readable representation of the error code | ||
@@ -127,3 +122,3 @@ * @return {keyof typeof Status} | ||
| */ | ||
| toJSON(): Omit<CustomError, 'addDetail' | 'serialize' | 'debug' | 'toJSON' | 'httpStatusCode'> & { | ||
| toJSON(): Omit<CustomError, 'addDetail' | 'serialize' | 'debug' | 'toJSON'> & { | ||
| debug?: DebugData; | ||
@@ -137,3 +132,8 @@ }; | ||
| static fromJSON(params: CustomErrorSerialized): CustomError; | ||
| /** | ||
| * An automatically determined HTTP status code | ||
| * @return {number} | ||
| */ | ||
| static suggestHttpResponseCode(err: Error | CustomError | unknown): number; | ||
| } | ||
| export {}; |
@@ -51,3 +51,3 @@ export var Status; | ||
| */ | ||
| cause; // can technically also be unknown, but would then conflict with other libs | ||
| cause; | ||
| /** | ||
@@ -97,9 +97,2 @@ * Further error details suitable for end user consumption | ||
| /** | ||
| * An automatically determined HTTP status code | ||
| * @return {number} | ||
| */ | ||
| get httpStatusCode() { | ||
| return defaultHttpMapping.get(this.code) || 500; | ||
| } | ||
| /** | ||
| * Human readable representation of the error code | ||
@@ -173,2 +166,10 @@ * @return {keyof typeof Status} | ||
| } | ||
| /** | ||
| * An automatically determined HTTP status code | ||
| * @return {number} | ||
| */ | ||
| static suggestHttpResponseCode(err) { | ||
| const code = CustomError.isCustomError(err) ? err.code : Status.UNKNOWN; | ||
| return defaultHttpMapping.get(code) || 500; | ||
| } | ||
| } | ||
@@ -175,0 +176,0 @@ // Mark all instances of 'CustomError' |
+10
-10
| { | ||
| "name": "@block65/custom-error", | ||
| "version": "10.0.1", | ||
| "version": "11.0.0", | ||
| "private": false, | ||
@@ -27,17 +27,17 @@ "license": "UNLICENSED", | ||
| "devDependencies": { | ||
| "@babel/core": "^7.18.9", | ||
| "@babel/preset-env": "^7.18.9", | ||
| "@babel/core": "^7.18.13", | ||
| "@babel/preset-env": "^7.18.10", | ||
| "@babel/preset-typescript": "^7.18.6", | ||
| "@block65/eslint-config": "^8.0.0", | ||
| "@types/jest": "^28.1.6", | ||
| "@types/node": "^18.0.6", | ||
| "@typescript-eslint/eslint-plugin": "^5.30.7", | ||
| "@typescript-eslint/parser": "^5.30.7", | ||
| "eslint": "^8.20.0", | ||
| "@types/jest": "^29.0.0", | ||
| "@types/node": "^18.7.14", | ||
| "@typescript-eslint/eslint-plugin": "^5.36.1", | ||
| "@typescript-eslint/parser": "^5.36.1", | ||
| "eslint": "^8.23.0", | ||
| "eslint-plugin-import": "^2.26.0", | ||
| "eslint-plugin-prettier": "^4.2.1", | ||
| "jest": "^28.1.3", | ||
| "jest": "^29.0.1", | ||
| "prettier": "^2.7.1", | ||
| "rimraf": "^3.0.2", | ||
| "typescript": "^4.7.4" | ||
| "typescript": "^4.8.2" | ||
| }, | ||
@@ -44,0 +44,0 @@ "engines": { |
13024
0.42%374
0.27%