@nice-code/common-errors 0.2.0 → 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/hono/index.js +15 -11
- package/build/index.js +15 -11
- package/package.json +2 -2
package/build/hono/index.js
CHANGED
|
@@ -357,7 +357,7 @@ var causePack = (error) => {
|
|
|
357
357
|
|
|
358
358
|
// ../nice-error/src/utils/packError/msgPack.ts
|
|
359
359
|
var msgPack = (error) => {
|
|
360
|
-
error._packedState = { message: error.
|
|
360
|
+
error._packedState = { message: error.cleanMessage, packedAs: "msg_pack" /* msg_pack */ };
|
|
361
361
|
error.message = `${DUR_OBJ_PACK_PREFIX}${JSON.stringify(error.toJsonObject())}${DUR_OBJ_PACK_SUFFIX}`;
|
|
362
362
|
return error;
|
|
363
363
|
};
|
|
@@ -381,11 +381,15 @@ class NiceError extends Error {
|
|
|
381
381
|
wasntNice;
|
|
382
382
|
httpStatusCode;
|
|
383
383
|
timeCreated;
|
|
384
|
+
cleanMessage;
|
|
384
385
|
originError;
|
|
385
386
|
_packedState;
|
|
386
387
|
_errorDataMap;
|
|
387
388
|
constructor(options) {
|
|
388
|
-
|
|
389
|
+
const messagePure = options.message;
|
|
390
|
+
const prefixedMessage = `[${options.def.domain}](${options.ids.join(",")}) ${messagePure}`;
|
|
391
|
+
super(prefixedMessage);
|
|
392
|
+
this.cleanMessage = messagePure;
|
|
389
393
|
this.def = options.def;
|
|
390
394
|
this.ids = options.ids;
|
|
391
395
|
this._errorDataMap = options.errorData;
|
|
@@ -443,7 +447,7 @@ class NiceError extends Error {
|
|
|
443
447
|
toJsonObject() {
|
|
444
448
|
const originError = this.originError ? {
|
|
445
449
|
name: this.originError.name,
|
|
446
|
-
message: this.originError.message,
|
|
450
|
+
message: this.originError.cleanMessage ?? this.originError.message,
|
|
447
451
|
stack: this.originError.stack,
|
|
448
452
|
cause: this.originError.cause
|
|
449
453
|
} : undefined;
|
|
@@ -474,7 +478,7 @@ class NiceError extends Error {
|
|
|
474
478
|
}
|
|
475
479
|
errorData[id] = {
|
|
476
480
|
contextState,
|
|
477
|
-
message: data.message,
|
|
481
|
+
message: data.cleanMessage ?? data.message,
|
|
478
482
|
httpStatusCode: data.httpStatusCode,
|
|
479
483
|
timeAdded: data.timeAdded
|
|
480
484
|
};
|
|
@@ -485,7 +489,7 @@ class NiceError extends Error {
|
|
|
485
489
|
ids: this.ids,
|
|
486
490
|
errorData,
|
|
487
491
|
wasntNice: this.wasntNice,
|
|
488
|
-
message: this.
|
|
492
|
+
message: this.cleanMessage,
|
|
489
493
|
httpStatusCode: this.httpStatusCode,
|
|
490
494
|
timeCreated: this.timeCreated,
|
|
491
495
|
...this.stack != null ? { stack: this.stack } : {},
|
|
@@ -579,7 +583,7 @@ class NiceErrorHydrated extends NiceError {
|
|
|
579
583
|
niceErrorDefined: this.niceErrorDefined,
|
|
580
584
|
ids: mergedIds,
|
|
581
585
|
errorData: mergedErrorData,
|
|
582
|
-
message: this.
|
|
586
|
+
message: this.cleanMessage,
|
|
583
587
|
wasntNice: this.wasntNice,
|
|
584
588
|
httpStatusCode: this.httpStatusCode,
|
|
585
589
|
originError: this.originError
|
|
@@ -600,7 +604,7 @@ class NiceErrorHydrated extends NiceError {
|
|
|
600
604
|
niceErrorDefined: this.niceErrorDefined,
|
|
601
605
|
ids: mergedIds,
|
|
602
606
|
errorData: mergedContexts,
|
|
603
|
-
message: this.
|
|
607
|
+
message: this.cleanMessage,
|
|
604
608
|
wasntNice: this.wasntNice,
|
|
605
609
|
httpStatusCode: this.httpStatusCode,
|
|
606
610
|
originError: this.originError
|
|
@@ -710,7 +714,7 @@ class NiceErrorDomain {
|
|
|
710
714
|
}
|
|
711
715
|
reconciledErrorData[id] = {
|
|
712
716
|
contextState,
|
|
713
|
-
message: existingData.message,
|
|
717
|
+
message: existingData.cleanMessage ?? existingData.message,
|
|
714
718
|
httpStatusCode: existingData.httpStatusCode,
|
|
715
719
|
timeAdded: existingData.timeAdded
|
|
716
720
|
};
|
|
@@ -720,7 +724,7 @@ class NiceErrorDomain {
|
|
|
720
724
|
niceErrorDefined: this,
|
|
721
725
|
ids: finalError.ids,
|
|
722
726
|
errorData: reconciledErrorData,
|
|
723
|
-
message: finalError.message,
|
|
727
|
+
message: finalError.cleanMessage ?? finalError.message,
|
|
724
728
|
httpStatusCode: finalError.httpStatusCode,
|
|
725
729
|
wasntNice: finalError.wasntNice,
|
|
726
730
|
originError: finalError.originError,
|
|
@@ -737,7 +741,7 @@ class NiceErrorDomain {
|
|
|
737
741
|
niceErrorDefined: this,
|
|
738
742
|
ids: [id],
|
|
739
743
|
errorData,
|
|
740
|
-
message: reconciledData.message,
|
|
744
|
+
message: reconciledData.cleanMessage ?? reconciledData.message,
|
|
741
745
|
httpStatusCode: reconciledData.httpStatusCode
|
|
742
746
|
});
|
|
743
747
|
}
|
|
@@ -756,7 +760,7 @@ class NiceErrorDomain {
|
|
|
756
760
|
niceErrorDefined: this,
|
|
757
761
|
ids,
|
|
758
762
|
errorData,
|
|
759
|
-
message: errorData[primaryId].message,
|
|
763
|
+
message: errorData[primaryId].cleanMessage ?? errorData[primaryId].message,
|
|
760
764
|
httpStatusCode: errorData[primaryId].httpStatusCode
|
|
761
765
|
});
|
|
762
766
|
}
|
package/build/index.js
CHANGED
|
@@ -357,7 +357,7 @@ var causePack = (error) => {
|
|
|
357
357
|
|
|
358
358
|
// ../nice-error/src/utils/packError/msgPack.ts
|
|
359
359
|
var msgPack = (error) => {
|
|
360
|
-
error._packedState = { message: error.
|
|
360
|
+
error._packedState = { message: error.cleanMessage, packedAs: "msg_pack" /* msg_pack */ };
|
|
361
361
|
error.message = `${DUR_OBJ_PACK_PREFIX}${JSON.stringify(error.toJsonObject())}${DUR_OBJ_PACK_SUFFIX}`;
|
|
362
362
|
return error;
|
|
363
363
|
};
|
|
@@ -381,11 +381,15 @@ class NiceError extends Error {
|
|
|
381
381
|
wasntNice;
|
|
382
382
|
httpStatusCode;
|
|
383
383
|
timeCreated;
|
|
384
|
+
cleanMessage;
|
|
384
385
|
originError;
|
|
385
386
|
_packedState;
|
|
386
387
|
_errorDataMap;
|
|
387
388
|
constructor(options) {
|
|
388
|
-
|
|
389
|
+
const messagePure = options.message;
|
|
390
|
+
const prefixedMessage = `[${options.def.domain}](${options.ids.join(",")}) ${messagePure}`;
|
|
391
|
+
super(prefixedMessage);
|
|
392
|
+
this.cleanMessage = messagePure;
|
|
389
393
|
this.def = options.def;
|
|
390
394
|
this.ids = options.ids;
|
|
391
395
|
this._errorDataMap = options.errorData;
|
|
@@ -443,7 +447,7 @@ class NiceError extends Error {
|
|
|
443
447
|
toJsonObject() {
|
|
444
448
|
const originError = this.originError ? {
|
|
445
449
|
name: this.originError.name,
|
|
446
|
-
message: this.originError.message,
|
|
450
|
+
message: this.originError.cleanMessage ?? this.originError.message,
|
|
447
451
|
stack: this.originError.stack,
|
|
448
452
|
cause: this.originError.cause
|
|
449
453
|
} : undefined;
|
|
@@ -474,7 +478,7 @@ class NiceError extends Error {
|
|
|
474
478
|
}
|
|
475
479
|
errorData[id] = {
|
|
476
480
|
contextState,
|
|
477
|
-
message: data.message,
|
|
481
|
+
message: data.cleanMessage ?? data.message,
|
|
478
482
|
httpStatusCode: data.httpStatusCode,
|
|
479
483
|
timeAdded: data.timeAdded
|
|
480
484
|
};
|
|
@@ -485,7 +489,7 @@ class NiceError extends Error {
|
|
|
485
489
|
ids: this.ids,
|
|
486
490
|
errorData,
|
|
487
491
|
wasntNice: this.wasntNice,
|
|
488
|
-
message: this.
|
|
492
|
+
message: this.cleanMessage,
|
|
489
493
|
httpStatusCode: this.httpStatusCode,
|
|
490
494
|
timeCreated: this.timeCreated,
|
|
491
495
|
...this.stack != null ? { stack: this.stack } : {},
|
|
@@ -579,7 +583,7 @@ class NiceErrorHydrated extends NiceError {
|
|
|
579
583
|
niceErrorDefined: this.niceErrorDefined,
|
|
580
584
|
ids: mergedIds,
|
|
581
585
|
errorData: mergedErrorData,
|
|
582
|
-
message: this.
|
|
586
|
+
message: this.cleanMessage,
|
|
583
587
|
wasntNice: this.wasntNice,
|
|
584
588
|
httpStatusCode: this.httpStatusCode,
|
|
585
589
|
originError: this.originError
|
|
@@ -600,7 +604,7 @@ class NiceErrorHydrated extends NiceError {
|
|
|
600
604
|
niceErrorDefined: this.niceErrorDefined,
|
|
601
605
|
ids: mergedIds,
|
|
602
606
|
errorData: mergedContexts,
|
|
603
|
-
message: this.
|
|
607
|
+
message: this.cleanMessage,
|
|
604
608
|
wasntNice: this.wasntNice,
|
|
605
609
|
httpStatusCode: this.httpStatusCode,
|
|
606
610
|
originError: this.originError
|
|
@@ -710,7 +714,7 @@ class NiceErrorDomain {
|
|
|
710
714
|
}
|
|
711
715
|
reconciledErrorData[id] = {
|
|
712
716
|
contextState,
|
|
713
|
-
message: existingData.message,
|
|
717
|
+
message: existingData.cleanMessage ?? existingData.message,
|
|
714
718
|
httpStatusCode: existingData.httpStatusCode,
|
|
715
719
|
timeAdded: existingData.timeAdded
|
|
716
720
|
};
|
|
@@ -720,7 +724,7 @@ class NiceErrorDomain {
|
|
|
720
724
|
niceErrorDefined: this,
|
|
721
725
|
ids: finalError.ids,
|
|
722
726
|
errorData: reconciledErrorData,
|
|
723
|
-
message: finalError.message,
|
|
727
|
+
message: finalError.cleanMessage ?? finalError.message,
|
|
724
728
|
httpStatusCode: finalError.httpStatusCode,
|
|
725
729
|
wasntNice: finalError.wasntNice,
|
|
726
730
|
originError: finalError.originError,
|
|
@@ -737,7 +741,7 @@ class NiceErrorDomain {
|
|
|
737
741
|
niceErrorDefined: this,
|
|
738
742
|
ids: [id],
|
|
739
743
|
errorData,
|
|
740
|
-
message: reconciledData.message,
|
|
744
|
+
message: reconciledData.cleanMessage ?? reconciledData.message,
|
|
741
745
|
httpStatusCode: reconciledData.httpStatusCode
|
|
742
746
|
});
|
|
743
747
|
}
|
|
@@ -756,7 +760,7 @@ class NiceErrorDomain {
|
|
|
756
760
|
niceErrorDefined: this,
|
|
757
761
|
ids,
|
|
758
762
|
errorData,
|
|
759
|
-
message: errorData[primaryId].message,
|
|
763
|
+
message: errorData[primaryId].cleanMessage ?? errorData[primaryId].message,
|
|
760
764
|
httpStatusCode: errorData[primaryId].httpStatusCode
|
|
761
765
|
});
|
|
762
766
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nice-code/common-errors",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"build-types": "tsc --project tsconfig.build.json"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@nice-code/error": "0.2.
|
|
32
|
+
"@nice-code/error": "0.2.2",
|
|
33
33
|
"@standard-schema/spec": "^1.1.0",
|
|
34
34
|
"@hono/standard-validator": "^0.2.2",
|
|
35
35
|
"http-status-codes": "^2.3.0"
|