@springworks/error-factory
Advanced tools
Comparing version 3005.76.0 to 3005.77.0
@@ -25,5 +25,6 @@ "use strict"; | ||
function createClientErrorForResponse(response) { | ||
var _a; | ||
let code = 'client-error'; | ||
let message = 'Client error'; | ||
if (response.body?.error) { | ||
if ((_a = response.body) === null || _a === void 0 ? void 0 : _a.error) { | ||
code = response.body.error.code; | ||
@@ -30,0 +31,0 @@ message = response.body.error.message; |
@@ -9,2 +9,3 @@ "use strict"; | ||
function getStatusCode(code, cause) { | ||
var _a; | ||
if (typeof code === 'number' && code >= 400 && http_1.STATUS_CODES[code]) { | ||
@@ -14,3 +15,3 @@ return code; | ||
if (cause) { | ||
if (cause.output?.statusCode) { | ||
if ((_a = cause.output) === null || _a === void 0 ? void 0 : _a.statusCode) { | ||
return getStatusCode(cause.output.statusCode, null); | ||
@@ -50,8 +51,9 @@ } | ||
function useParamsOrDefaults(params) { | ||
return params ?? {}; | ||
return params !== null && params !== void 0 ? 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 ?? createError); | ||
Error.captureStackTrace(error, stack_from !== null && stack_from !== void 0 ? stack_from : createError); | ||
const error_code = getStatusCode(code, cause); | ||
@@ -63,3 +65,3 @@ boom_1.boomify(error, { statusCode: error_code }); | ||
error.output.payload.error_id = error_id; | ||
const root_id = getRootErrorId(root_error_id, cause) ?? error_id; | ||
const root_id = (_a = getRootErrorId(root_error_id, cause)) !== null && _a !== void 0 ? _a : error_id; | ||
error.root_error_id = root_id; | ||
@@ -75,3 +77,3 @@ error.output.payload.root_error_id = root_id; | ||
} | ||
if (cause?.output?.headers) { | ||
if ((_b = cause === null || cause === void 0 ? void 0 : cause.output) === null || _b === void 0 ? void 0 : _b.headers) { | ||
error.output.headers = cause.output.headers; | ||
@@ -78,0 +80,0 @@ } |
@@ -6,2 +6,13 @@ # Change Log | ||
# [3005.77.0](https://github.com/Springworks/m2h-mono/compare/v3005.76.0...v3005.77.0) (2021-08-23) | ||
### Features | ||
* force update all packages ([0ba911e](https://github.com/Springworks/m2h-mono/commit/0ba911efe4915423de9ffc654261f76f14980513)) | ||
# [3005.76.0](https://github.com/Springworks/m2h-mono/compare/v3005.75.2...v3005.76.0) (2021-08-23) | ||
@@ -8,0 +19,0 @@ |
{ | ||
"name": "@springworks/error-factory", | ||
"version": "3005.76.0", | ||
"version": "3005.77.0", | ||
"description": "Custom error that makes use of HTTP error codes to identify different error types.", | ||
@@ -13,4 +13,4 @@ "main": "build/main.js", | ||
"@hapi/boom": "^9.0.0", | ||
"@springworks/random-string": "3005.76.0", | ||
"@springworks/swagger-schema-interfaces": "3005.76.0" | ||
"@springworks/random-string": "3005.77.0", | ||
"@springworks/swagger-schema-interfaces": "3005.77.0" | ||
}, | ||
@@ -30,3 +30,3 @@ "devDependencies": { | ||
"homepage": "https://github.com/Springworks/m2h-mono/tree/master/packages/error-factory#readme", | ||
"gitHead": "ab6e347684e7a8e77b4e87fb8940039899036d0c" | ||
"gitHead": "7a75343c9d8a134e44647bc2d4007cb1eeebf02a" | ||
} |
Sorry, the diff of this file is not supported yet
44815
514
+ Added@springworks/random-string@3005.77.0(transitive)
- Removed@springworks/random-string@3005.76.0(transitive)