@springworks/error-factory
Advanced tools
Comparing version 3005.44.0 to 3005.76.0
@@ -25,6 +25,5 @@ "use strict"; | ||
function createClientErrorForResponse(response) { | ||
var _a; | ||
let code = 'client-error'; | ||
let message = 'Client error'; | ||
if ((_a = response.body) === null || _a === void 0 ? void 0 : _a.error) { | ||
if (response.body?.error) { | ||
code = response.body.error.code; | ||
@@ -31,0 +30,0 @@ message = response.body.error.message; |
@@ -9,3 +9,2 @@ "use strict"; | ||
function getStatusCode(code, cause) { | ||
var _a; | ||
if (typeof code === 'number' && code >= 400 && http_1.STATUS_CODES[code]) { | ||
@@ -15,3 +14,3 @@ return code; | ||
if (cause) { | ||
if ((_a = cause.output) === null || _a === void 0 ? void 0 : _a.statusCode) { | ||
if (cause.output?.statusCode) { | ||
return getStatusCode(cause.output.statusCode, null); | ||
@@ -51,9 +50,8 @@ } | ||
function useParamsOrDefaults(params) { | ||
return params !== null && params !== void 0 ? params : {}; | ||
return params ?? {}; | ||
} | ||
function createError(params) { | ||
var _a, _b; | ||
const { code, message, cause, root_error_id, stack_from } = useParamsOrDefaults(params); | ||
const error = new Error(message !== null ? message : undefined); | ||
Error.captureStackTrace(error, stack_from !== null && stack_from !== void 0 ? stack_from : createError); | ||
Error.captureStackTrace(error, stack_from ?? createError); | ||
const error_code = getStatusCode(code, cause); | ||
@@ -65,3 +63,3 @@ boom_1.boomify(error, { statusCode: error_code }); | ||
error.output.payload.error_id = error_id; | ||
const root_id = (_a = getRootErrorId(root_error_id, cause)) !== null && _a !== void 0 ? _a : error_id; | ||
const root_id = getRootErrorId(root_error_id, cause) ?? error_id; | ||
error.root_error_id = root_id; | ||
@@ -77,3 +75,3 @@ error.output.payload.root_error_id = root_id; | ||
} | ||
if ((_b = cause === null || cause === void 0 ? void 0 : cause.output) === null || _b === void 0 ? void 0 : _b.headers) { | ||
if (cause?.output?.headers) { | ||
error.output.headers = cause.output.headers; | ||
@@ -80,0 +78,0 @@ } |
@@ -6,2 +6,10 @@ # Change Log | ||
# [3005.76.0](https://github.com/Springworks/m2h-mono/compare/v3005.75.2...v3005.76.0) (2021-08-23) | ||
**Note:** Version bump only for package @springworks/error-factory | ||
# [3005.44.0](https://github.com/Springworks/m2h-mono/compare/v3005.43.2...v3005.44.0) (2021-04-14) | ||
@@ -8,0 +16,0 @@ |
{ | ||
"name": "@springworks/error-factory", | ||
"version": "3005.44.0", | ||
"version": "3005.76.0", | ||
"description": "Custom error that makes use of HTTP error codes to identify different error types.", | ||
@@ -10,10 +10,7 @@ "main": "build/main.js", | ||
], | ||
"scripts": { | ||
"lint": "tslint --project tsconfig.json --format stylish", | ||
"lint-fix": "tslint --project tsconfig.json --format stylish --fix" | ||
}, | ||
"scripts": {}, | ||
"dependencies": { | ||
"@hapi/boom": "^9.0.0", | ||
"@springworks/random-string": "3005.14.3", | ||
"@springworks/swagger-schema-interfaces": "3005.44.0" | ||
"@springworks/random-string": "3005.76.0", | ||
"@springworks/swagger-schema-interfaces": "3005.76.0" | ||
}, | ||
@@ -33,3 +30,3 @@ "devDependencies": { | ||
"homepage": "https://github.com/Springworks/m2h-mono/tree/master/packages/error-factory#readme", | ||
"gitHead": "fdad9fd84c703c797215a34ecb8b755a6bc315ed" | ||
"gitHead": "ab6e347684e7a8e77b4e87fb8940039899036d0c" | ||
} |
44221
511
+ Added@springworks/random-string@3005.76.0(transitive)
- Removed@springworks/random-string@3005.14.3(transitive)