Comparing version 1.2.1 to 1.2.2
@@ -17,2 +17,4 @@ import ExtendableError from 'es6-error'; | ||
protected _config: IBaseErrorConfig; | ||
protected _hasMetadata: boolean; | ||
protected _hasSafeMetadata: boolean; | ||
constructor(message: string, config?: IBaseErrorConfig); | ||
@@ -19,0 +21,0 @@ /** |
@@ -17,2 +17,4 @@ "use strict"; | ||
this._metadata = {}; | ||
this._hasMetadata = false; | ||
this._hasSafeMetadata = false; | ||
this._config = config || {}; | ||
@@ -156,2 +158,3 @@ } | ||
withMetadata(metadata) { | ||
this._hasMetadata = true; | ||
this._metadata = { | ||
@@ -177,2 +180,4 @@ ...this._metadata, | ||
withSafeMetadata(metadata) { | ||
this._hasMetadata = true; | ||
this._hasSafeMetadata = true; | ||
this._safeMetadata = { | ||
@@ -209,2 +214,7 @@ ...this._safeMetadata, | ||
}; | ||
if (!this._hasSafeMetadata && | ||
!this._hasMetadata && | ||
this._config.omitEmptyMetadata) { | ||
delete data.meta; | ||
} | ||
Object.keys(data).forEach(item => { | ||
@@ -240,2 +250,5 @@ // remove undefined items | ||
}; | ||
if (!this._hasSafeMetadata && this._config.omitEmptyMetadata) { | ||
delete data.meta; | ||
} | ||
Object.keys(data).forEach(item => { | ||
@@ -302,3 +315,3 @@ // remove undefined items | ||
else { | ||
errInstance.withMetadata(data.meta); | ||
errInstance.withMetadata(data.meta || {}); | ||
} | ||
@@ -305,0 +318,0 @@ } |
@@ -211,2 +211,6 @@ /** | ||
toJSONSafeFieldsToOmit?: string[]; | ||
/** | ||
* If the metadata has no data defined, remove the `meta` property on `toJSON` / `toJSONSafe` | ||
*/ | ||
omitEmptyMetadata?: boolean; | ||
} | ||
@@ -213,0 +217,0 @@ /** |
@@ -0,1 +1,9 @@ | ||
## 1.2.2 - Mon Mar 08 2021 21:06:07 | ||
**Contributor:** Theo Gravity | ||
- Add option to not include empty metadata on serialization (#9) | ||
This adds `omitEmptyMetadata` to the `BaseError` configuration. | ||
## 1.2.1 - Mon Mar 08 2021 20:33:41 | ||
@@ -2,0 +10,0 @@ |
{ | ||
"name": "new-error", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "A production-grade error creation and serialization library designed for Typescript", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -489,2 +489,6 @@ # new-error | ||
toJSONSafeFieldsToOmit?: string[] | ||
/** | ||
* If the metadata has no data defined, remove the `meta` property on `toJSON` / `toJSONSafe`. | ||
*/ | ||
omitEmptyMetadata?: boolean | ||
} | ||
@@ -491,0 +495,0 @@ ``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
77812
100
1042
861