@nice-code/error 0.2.16 → 0.2.17

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.
package/build/index.js CHANGED
@@ -178,6 +178,9 @@ class NiceError extends Error {
178
178
  originError
179
179
  };
180
180
  }
181
+ toJSON() {
182
+ return this.toJsonObject();
183
+ }
181
184
  toJsonString() {
182
185
  return JSON.stringify(this.toJsonObject());
183
186
  }
@@ -418,7 +421,7 @@ class NiceErrorDomain {
418
421
  const reconciledData = this.reconcileErrorDataForId(id, context);
419
422
  const errorData = {};
420
423
  errorData[id] = reconciledData;
421
- return this.createError({
424
+ const err = this.createError({
422
425
  def: this._buildDef(),
423
426
  niceErrorDefined: this,
424
427
  ids: [id],
@@ -426,6 +429,10 @@ class NiceErrorDomain {
426
429
  message: reconciledData.cleanMessage ?? reconciledData.message,
427
430
  httpStatusCode: reconciledData.httpStatusCode
428
431
  });
432
+ if (typeof Error.captureStackTrace === "function") {
433
+ Error.captureStackTrace(err, this.fromId);
434
+ }
435
+ return err;
429
436
  }
430
437
  fromContext(context) {
431
438
  const ids = Object.keys(context);
@@ -437,7 +444,7 @@ class NiceErrorDomain {
437
444
  errorData[id] = this.reconcileErrorDataForId(id, context[id]);
438
445
  }
439
446
  const primaryId = ids[0];
440
- return this.createError({
447
+ const err = this.createError({
441
448
  def: this._buildDef(),
442
449
  niceErrorDefined: this,
443
450
  ids,
@@ -445,6 +452,10 @@ class NiceErrorDomain {
445
452
  message: errorData[primaryId].cleanMessage ?? errorData[primaryId].message,
446
453
  httpStatusCode: errorData[primaryId].httpStatusCode
447
454
  });
455
+ if (typeof Error.captureStackTrace === "function") {
456
+ Error.captureStackTrace(err, this.fromContext);
457
+ }
458
+ return err;
448
459
  }
449
460
  isExact(error) {
450
461
  if (!(error instanceof NiceError))
@@ -92,6 +92,7 @@ ACTIVE_IDS extends TDomainNiceErrorId<ERR_DEF> = TDomainNiceErrorId<ERR_DEF>> ex
92
92
  */
93
93
  matches(other: NiceError<any, any>): boolean;
94
94
  toJsonObject(): INiceErrorJsonObject<ERR_DEF>;
95
+ toJSON(): INiceErrorJsonObject<ERR_DEF>;
95
96
  toJsonString(): string;
96
97
  toHttpResponse(): Response;
97
98
  hydrate(definedNiceError: NiceErrorDomain<ERR_DEF>): NiceErrorHydrated<ERR_DEF, ACTIVE_IDS>;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "module": "build/index.js",
5
5
  "types": "build/types/index.d.ts",
6
6
  "type": "module",
7
- "version": "0.2.16",
7
+ "version": "0.2.17",
8
8
  "exports": {
9
9
  ".": {
10
10
  "source": "./src/index.ts",