core-functions
Advanced tools
Comparing version 3.0.8 to 3.0.9
@@ -81,2 +81,12 @@ "use strict"; | ||
if (this.causeStatus) json.causeStatus = this.causeStatus; | ||
// Copy any and all enumerable own properties across too | ||
const names = Object.keys(this); //.filter(n => !json.hasOwnProperty(n)); | ||
for (let i = 0; i < names.length; ++i) { | ||
const name = names[i]; | ||
const value = this[name]; | ||
if (value !== undefined && typeof value !== 'function') { | ||
json[name] = value; | ||
} | ||
} | ||
return json; | ||
@@ -83,0 +93,0 @@ } |
{ | ||
"name": "core-functions", | ||
"version": "3.0.8", | ||
"version": "3.0.9", | ||
"description": "Core functions, utilities and classes for working with Node/JavaScript primitives and built-in objects, including strings, booleans, Promises, base 64, Arrays, Objects, standard AppErrors, etc.", | ||
@@ -5,0 +5,0 @@ "author": "Byron du Preez", |
@@ -1,2 +0,2 @@ | ||
# core-functions v3.0.8 | ||
# core-functions v3.0.9 | ||
@@ -3,0 +3,0 @@ Core functions, utilities and classes for working with Node/JavaScript primitives and built-in objects, including |
## Changes | ||
### 3.0.9 | ||
- Fixed `toJSON` method in `AppError` class to also include any enumerable own properties | ||
### 3.0.8 | ||
@@ -4,0 +7,0 @@ - Added a new `errors` module with a new `FatalError` class |
@@ -395,6 +395,6 @@ 'use strict'; | ||
// Check errors with httpStatusCode, httpStatus & statusCode become appropriate errors | ||
check({httpStatusCode: " 400 ", httpStatus: " 401 ", statusCode: " 404 " }, BadRequest); | ||
check({httpStatusCode: "MY 400 ", httpStatus: " 401 ", statusCode: " 404 " }, Unauthorized); | ||
check({httpStatusCode: "MY 400 ", httpStatus: "MY 401 ", statusCode: " 404 " }, NotFound); | ||
check({httpStatusCode: "MY 400 ", httpStatus: "MY 401 ", statusCode: "MY 404 " }, InternalServerError); | ||
check({httpStatusCode: " 400 ", httpStatus: " 401 ", statusCode: " 404 "}, BadRequest); | ||
check({httpStatusCode: "MY 400 ", httpStatus: " 401 ", statusCode: " 404 "}, Unauthorized); | ||
check({httpStatusCode: "MY 400 ", httpStatus: "MY 401 ", statusCode: " 404 "}, NotFound); | ||
check({httpStatusCode: "MY 400 ", httpStatus: "MY 401 ", statusCode: "MY 404 "}, InternalServerError); | ||
@@ -451,8 +451,30 @@ // Check default unsupported AppErrors get changed | ||
const json = {message: e.message, code: e.code, httpStatus: e.httpStatus, cause: e.cause}; | ||
const jsonText = JSON.stringify(json); | ||
let json = {message: e.message, code: e.code, httpStatus: e.httpStatus, cause: e.cause}; | ||
let jsonText = JSON.stringify(json); | ||
t.deepEqual(e.toJSON(), json, `${e} toJSON must be ${jsonText}`); | ||
t.deepEqual(JSON.parse(JSON.stringify(e)), json, `JSON.parse(JSON.stringify(${e})) must be ${jsonText}`); | ||
// Add additional enumerable properties | ||
e.awsRequestId = 'e72617f3-4cb2-40ba-9a16-e75b3e4226cf'; | ||
e.nowYouSeeMe = "Now you don't"; | ||
json = { | ||
message: e.message, code: e.code, httpStatus: e.httpStatus, cause: e.cause, awsRequestId: e.awsRequestId, | ||
nowYouSeeMe: e.nowYouSeeMe | ||
}; | ||
jsonText = JSON.stringify(json); | ||
t.deepEqual(e.toJSON(), json, `${e} toJSON must be ${jsonText}`); | ||
t.deepEqual(JSON.parse(JSON.stringify(e)), json, `JSON.parse(JSON.stringify(${e})) must be ${jsonText}`); | ||
// Change nowYouSeeMe to non-enumerable | ||
Object.defineProperty(e, 'nowYouSeeMe', {enumerable: false}); | ||
json = { | ||
message: e.message, code: e.code, httpStatus: e.httpStatus, cause: e.cause, awsRequestId: e.awsRequestId | ||
}; | ||
jsonText = JSON.stringify(json); | ||
t.deepEqual(e.toJSON(), json, `${e} toJSON must be ${jsonText}`); | ||
t.deepEqual(JSON.parse(JSON.stringify(e)), json, `JSON.parse(JSON.stringify(${e})) must be ${jsonText}`); | ||
t.end(); | ||
}); |
924274
14724