@nice-code/error 0.2.1 → 0.2.2

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
@@ -365,7 +365,7 @@ var causePack = (error) => {
365
365
 
366
366
  // src/utils/packError/msgPack.ts
367
367
  var msgPack = (error) => {
368
- error._packedState = { message: error.message, packedAs: "msg_pack" /* msg_pack */ };
368
+ error._packedState = { message: error.cleanMessage, packedAs: "msg_pack" /* msg_pack */ };
369
369
  error.message = `${DUR_OBJ_PACK_PREFIX}${JSON.stringify(error.toJsonObject())}${DUR_OBJ_PACK_SUFFIX}`;
370
370
  return error;
371
371
  };
@@ -389,11 +389,15 @@ class NiceError extends Error {
389
389
  wasntNice;
390
390
  httpStatusCode;
391
391
  timeCreated;
392
+ cleanMessage;
392
393
  originError;
393
394
  _packedState;
394
395
  _errorDataMap;
395
396
  constructor(options) {
396
- super(options.message);
397
+ const messagePure = options.message;
398
+ const prefixedMessage = `[${options.def.domain}](${options.ids.join(",")}) ${messagePure}`;
399
+ super(prefixedMessage);
400
+ this.cleanMessage = messagePure;
397
401
  this.def = options.def;
398
402
  this.ids = options.ids;
399
403
  this._errorDataMap = options.errorData;
@@ -451,7 +455,7 @@ class NiceError extends Error {
451
455
  toJsonObject() {
452
456
  const originError = this.originError ? {
453
457
  name: this.originError.name,
454
- message: this.originError.message,
458
+ message: this.originError.cleanMessage ?? this.originError.message,
455
459
  stack: this.originError.stack,
456
460
  cause: this.originError.cause
457
461
  } : undefined;
@@ -482,7 +486,7 @@ class NiceError extends Error {
482
486
  }
483
487
  errorData[id] = {
484
488
  contextState,
485
- message: data.message,
489
+ message: data.cleanMessage ?? data.message,
486
490
  httpStatusCode: data.httpStatusCode,
487
491
  timeAdded: data.timeAdded
488
492
  };
@@ -493,7 +497,7 @@ class NiceError extends Error {
493
497
  ids: this.ids,
494
498
  errorData,
495
499
  wasntNice: this.wasntNice,
496
- message: this.message,
500
+ message: this.cleanMessage,
497
501
  httpStatusCode: this.httpStatusCode,
498
502
  timeCreated: this.timeCreated,
499
503
  ...this.stack != null ? { stack: this.stack } : {},
@@ -587,7 +591,7 @@ class NiceErrorHydrated extends NiceError {
587
591
  niceErrorDefined: this.niceErrorDefined,
588
592
  ids: mergedIds,
589
593
  errorData: mergedErrorData,
590
- message: this.message,
594
+ message: this.cleanMessage,
591
595
  wasntNice: this.wasntNice,
592
596
  httpStatusCode: this.httpStatusCode,
593
597
  originError: this.originError
@@ -608,7 +612,7 @@ class NiceErrorHydrated extends NiceError {
608
612
  niceErrorDefined: this.niceErrorDefined,
609
613
  ids: mergedIds,
610
614
  errorData: mergedContexts,
611
- message: this.message,
615
+ message: this.cleanMessage,
612
616
  wasntNice: this.wasntNice,
613
617
  httpStatusCode: this.httpStatusCode,
614
618
  originError: this.originError
@@ -718,7 +722,7 @@ class NiceErrorDomain {
718
722
  }
719
723
  reconciledErrorData[id] = {
720
724
  contextState,
721
- message: existingData.message,
725
+ message: existingData.cleanMessage ?? existingData.message,
722
726
  httpStatusCode: existingData.httpStatusCode,
723
727
  timeAdded: existingData.timeAdded
724
728
  };
@@ -728,7 +732,7 @@ class NiceErrorDomain {
728
732
  niceErrorDefined: this,
729
733
  ids: finalError.ids,
730
734
  errorData: reconciledErrorData,
731
- message: finalError.message,
735
+ message: finalError.cleanMessage ?? finalError.message,
732
736
  httpStatusCode: finalError.httpStatusCode,
733
737
  wasntNice: finalError.wasntNice,
734
738
  originError: finalError.originError,
@@ -745,7 +749,7 @@ class NiceErrorDomain {
745
749
  niceErrorDefined: this,
746
750
  ids: [id],
747
751
  errorData,
748
- message: reconciledData.message,
752
+ message: reconciledData.cleanMessage ?? reconciledData.message,
749
753
  httpStatusCode: reconciledData.httpStatusCode
750
754
  });
751
755
  }
@@ -764,7 +768,7 @@ class NiceErrorDomain {
764
768
  niceErrorDefined: this,
765
769
  ids,
766
770
  errorData,
767
- message: errorData[primaryId].message,
771
+ message: errorData[primaryId].cleanMessage ?? errorData[primaryId].message,
768
772
  httpStatusCode: errorData[primaryId].httpStatusCode
769
773
  });
770
774
  }
@@ -34,6 +34,7 @@ ACTIVE_IDS extends TDomainNiceErrorId<ERR_DEF> = TDomainNiceErrorId<ERR_DEF>> ex
34
34
  readonly wasntNice: boolean;
35
35
  readonly httpStatusCode: number;
36
36
  readonly timeCreated: number;
37
+ readonly cleanMessage: string;
37
38
  originError?: IRegularErrorJsonObject;
38
39
  _packedState?: {
39
40
  packedAs: EErrorPackType.cause_pack;
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.1",
7
+ "version": "0.2.2",
8
8
  "exports": {
9
9
  ".": {
10
10
  "types": "./build/types/index.d.ts",