@naturalcycles/js-lib 14.106.0 → 14.107.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,3 +24,16 @@ export declare function _isHttpErrorObject(o: any): o is ErrorObject<HttpErrorDa
24
24
  * Note: any instance of AppError is also automatically an ErrorObject
25
25
  */
26
26
  export declare function _isErrorObject(o: any): o is ErrorObject;
27
+ /**
28
+ * Convenience function to safely add properties to Error's `data` object
29
+ * (even if it wasn't previously existing)
30
+ *
31
+ * @example
32
+ *
33
+ * try {} catch (err) {
34
+ * _errorDataAppend(err, {
35
+ * httpStatusCode: 401,
36
+ * })
37
+ * }
38
+ */
39
+ export declare function _errorDataAppend(err: Error, data: ErrorData): void;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._isErrorObject = exports._isHttpErrorObject = exports._isHttpErrorResponse = exports._errorObjectToError = exports._errorObjectToAppError = exports._errorToErrorObject = exports._anyToErrorObject = exports._anyToError = void 0;
3
+ exports._errorDataAppend = exports._isErrorObject = exports._isHttpErrorObject = exports._isHttpErrorResponse = exports._errorObjectToError = exports._errorObjectToAppError = exports._errorToErrorObject = exports._anyToErrorObject = exports._anyToError = void 0;
4
4
  const __1 = require("..");
5
5
  /**
6
6
  * Useful to ensure that error in `catch (err) { ... }`
@@ -108,3 +108,23 @@ function _isErrorObject(o) {
108
108
  return (!!o && typeof o.name === 'string' && typeof o.message === 'string' && typeof o.data === 'object');
109
109
  }
110
110
  exports._isErrorObject = _isErrorObject;
111
+ /**
112
+ * Convenience function to safely add properties to Error's `data` object
113
+ * (even if it wasn't previously existing)
114
+ *
115
+ * @example
116
+ *
117
+ * try {} catch (err) {
118
+ * _errorDataAppend(err, {
119
+ * httpStatusCode: 401,
120
+ * })
121
+ * }
122
+ */
123
+ function _errorDataAppend(err, data) {
124
+ ;
125
+ err.data = {
126
+ ...err.data,
127
+ ...data,
128
+ };
129
+ }
130
+ exports._errorDataAppend = _errorDataAppend;
@@ -96,3 +96,19 @@ export function _isHttpErrorObject(o) {
96
96
  export function _isErrorObject(o) {
97
97
  return (!!o && typeof o.name === 'string' && typeof o.message === 'string' && typeof o.data === 'object');
98
98
  }
99
+ /**
100
+ * Convenience function to safely add properties to Error's `data` object
101
+ * (even if it wasn't previously existing)
102
+ *
103
+ * @example
104
+ *
105
+ * try {} catch (err) {
106
+ * _errorDataAppend(err, {
107
+ * httpStatusCode: 401,
108
+ * })
109
+ * }
110
+ */
111
+ export function _errorDataAppend(err, data) {
112
+ ;
113
+ err.data = Object.assign(Object.assign({}, err.data), data);
114
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.106.0",
3
+ "version": "14.107.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -145,3 +145,22 @@ export function _isErrorObject(o: any): o is ErrorObject {
145
145
  !!o && typeof o.name === 'string' && typeof o.message === 'string' && typeof o.data === 'object'
146
146
  )
147
147
  }
148
+
149
+ /**
150
+ * Convenience function to safely add properties to Error's `data` object
151
+ * (even if it wasn't previously existing)
152
+ *
153
+ * @example
154
+ *
155
+ * try {} catch (err) {
156
+ * _errorDataAppend(err, {
157
+ * httpStatusCode: 401,
158
+ * })
159
+ * }
160
+ */
161
+ export function _errorDataAppend(err: Error, data: ErrorData): void {
162
+ ;(err as any).data = {
163
+ ...(err as any).data,
164
+ ...data,
165
+ }
166
+ }