@opra/common 0.23.0 → 0.23.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/browser.js +89 -84
- package/cjs/document/data-type/union-type.js +1 -1
- package/cjs/document/utils/generate-codec.js +1 -1
- package/cjs/exception/http-errors/bad-request.error.js +2 -3
- package/cjs/exception/http-errors/failed-dependency.error.js +2 -3
- package/cjs/exception/http-errors/forbidden.error.js +2 -3
- package/cjs/exception/http-errors/internal-server.error.js +2 -3
- package/cjs/exception/http-errors/method-not-allowed.error.js +2 -3
- package/cjs/exception/http-errors/not-acceptable.error.js +2 -3
- package/cjs/exception/http-errors/not-found.error.js +2 -3
- package/cjs/exception/http-errors/unauthorized.error.js +2 -3
- package/cjs/exception/http-errors/unprocessable-entity.error.js +2 -2
- package/cjs/exception/opra-exception.js +48 -33
- package/cjs/exception/resource-errors/resource-not-found.error.js +1 -2
- package/cjs/exception/wrap-exception.js +16 -16
- package/cjs/helpers/is-url-string.js +1 -2
- package/esm/document/data-type/union-type.js +1 -1
- package/esm/document/utils/generate-codec.js +1 -1
- package/esm/exception/http-errors/bad-request.error.js +2 -3
- package/esm/exception/http-errors/failed-dependency.error.js +2 -3
- package/esm/exception/http-errors/forbidden.error.js +2 -3
- package/esm/exception/http-errors/internal-server.error.js +2 -3
- package/esm/exception/http-errors/method-not-allowed.error.js +2 -3
- package/esm/exception/http-errors/not-acceptable.error.js +2 -3
- package/esm/exception/http-errors/not-found.error.js +2 -3
- package/esm/exception/http-errors/unauthorized.error.js +2 -3
- package/esm/exception/http-errors/unprocessable-entity.error.js +2 -2
- package/esm/exception/opra-exception.js +47 -32
- package/esm/exception/resource-errors/resource-not-found.error.js +1 -2
- package/esm/exception/wrap-exception.js +16 -16
- package/esm/helpers/is-url-string.js +0 -1
- package/package.json +5 -5
- package/types/document/data-type/complex-type.d.ts +1 -1
- package/types/document/data-type/mapped-type.d.ts +1 -1
- package/types/document/data-type/union-type.d.ts +2 -1
- package/types/document/resource/resource.d.ts +1 -1
- package/types/exception/error-issue.d.ts +2 -1
- package/types/exception/http-errors/bad-request.error.d.ts +2 -1
- package/types/exception/http-errors/failed-dependency.error.d.ts +2 -1
- package/types/exception/http-errors/forbidden.error.d.ts +2 -1
- package/types/exception/http-errors/internal-server.error.d.ts +2 -1
- package/types/exception/http-errors/method-not-allowed.error.d.ts +2 -1
- package/types/exception/http-errors/not-acceptable.error.d.ts +2 -1
- package/types/exception/http-errors/not-found.error.d.ts +2 -1
- package/types/exception/http-errors/unauthorized.error.d.ts +2 -1
- package/types/exception/http-errors/unprocessable-entity.error.d.ts +2 -1
- package/types/exception/opra-exception.d.ts +13 -8
- package/types/exception/wrap-exception.d.ts +1 -1
- package/types/helpers/object-utils.d.ts +1 -1
- package/types/schema/data-type/complex-type.interface.d.ts +1 -1
- package/types/schema/resource/resource.interface.d.ts +0 -1
- package/types/schema/resource/storage.interface.d.ts +1 -1
package/browser.js
CHANGED
|
@@ -18,12 +18,6 @@ var METADATA_KEY = Symbol.for("opra.metadata");
|
|
|
18
18
|
var NAMESPACE_PATTERN = /([A-Z$_]\w+)(?::.+)?/i;
|
|
19
19
|
var TYPENAME_PATTERN = /^(.*)Type(\d*)$/;
|
|
20
20
|
|
|
21
|
-
// ../../build/common/esm/i18n/i18n.js
|
|
22
|
-
import { splitString, tokenize } from "fast-tokenizer";
|
|
23
|
-
import fs from "@browsery/fs";
|
|
24
|
-
import path from "path-browserify";
|
|
25
|
-
import i18next from "@browsery/i18next";
|
|
26
|
-
|
|
27
21
|
// ../../build/common/esm/helpers/function-utils.js
|
|
28
22
|
import promisify from "putil-promisify";
|
|
29
23
|
|
|
@@ -110,7 +104,6 @@ function getStackFileName(position = 1) {
|
|
|
110
104
|
__name(getStackFileName, "getStackFileName");
|
|
111
105
|
|
|
112
106
|
// ../../build/common/esm/helpers/is-url-string.js
|
|
113
|
-
import { URL } from "url";
|
|
114
107
|
var URL_PATTERN = /^(https?:\/\/.)[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)$/i;
|
|
115
108
|
function isUrlString(url) {
|
|
116
109
|
return URL_PATTERN.test(url);
|
|
@@ -368,6 +361,12 @@ var ResponsiveMap = class extends Map {
|
|
|
368
361
|
}
|
|
369
362
|
};
|
|
370
363
|
|
|
364
|
+
// ../../build/common/esm/i18n/i18n.js
|
|
365
|
+
import { splitString, tokenize } from "fast-tokenizer";
|
|
366
|
+
import fs from "@browsery/fs";
|
|
367
|
+
import path from "path-browserify";
|
|
368
|
+
import i18next from "@browsery/i18next";
|
|
369
|
+
|
|
371
370
|
// ../../build/common/esm/i18n/string-utils.js
|
|
372
371
|
var unescapeRegEx = /\\(.)/g;
|
|
373
372
|
var escapeRegEx = /(\\)/g;
|
|
@@ -548,53 +547,68 @@ var i18n = I18n.createInstance();
|
|
|
548
547
|
i18n.init().catch(() => void 0);
|
|
549
548
|
|
|
550
549
|
// ../../build/common/esm/exception/opra-exception.js
|
|
550
|
+
var inDevelopment = (process.env.NODE_ENV || "").startsWith("dev");
|
|
551
551
|
var OpraException = class extends Error {
|
|
552
552
|
static {
|
|
553
553
|
__name(this, "OpraException");
|
|
554
554
|
}
|
|
555
|
-
constructor(issue,
|
|
556
|
-
super("");
|
|
555
|
+
constructor(issue, arg1, arg2) {
|
|
556
|
+
super("Unknown error");
|
|
557
557
|
this.status = 500;
|
|
558
|
-
|
|
558
|
+
let cause = arg1 && arg1 instanceof Error ? arg1 : void 0;
|
|
559
|
+
this.status = (typeof arg1 === "number" ? arg1 : Number(arg2)) || 500;
|
|
559
560
|
if (issue instanceof Error)
|
|
560
561
|
cause = issue;
|
|
561
|
-
if (cause) {
|
|
562
|
+
if (cause && cause instanceof Error) {
|
|
562
563
|
this.cause = cause;
|
|
563
564
|
if (cause.stack)
|
|
564
565
|
this.stack = cause.stack;
|
|
565
566
|
}
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
this._issue = {
|
|
574
|
-
message: "Unknown error",
|
|
575
|
-
severity: "error",
|
|
576
|
-
...issue
|
|
577
|
-
};
|
|
567
|
+
if (typeof issue === "string")
|
|
568
|
+
this.initString(issue);
|
|
569
|
+
else if (issue instanceof Error)
|
|
570
|
+
this.initError(issue);
|
|
571
|
+
else if (issue && typeof issue === "object")
|
|
572
|
+
this.init(issue);
|
|
573
|
+
this.message = this.message || this.constructor.name;
|
|
578
574
|
}
|
|
579
575
|
setStatus(status) {
|
|
580
576
|
this.status = status;
|
|
581
577
|
return this;
|
|
582
578
|
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
579
|
+
toString() {
|
|
580
|
+
return i18n.deep(this.message);
|
|
581
|
+
}
|
|
582
|
+
toJSON() {
|
|
583
|
+
return omitUndefined({
|
|
584
|
+
message: this.message,
|
|
585
|
+
severity: this.severity,
|
|
586
|
+
system: this.system,
|
|
587
|
+
code: this.code,
|
|
588
|
+
details: this.details,
|
|
589
|
+
stack: inDevelopment ? this.stack?.split("\n") : void 0
|
|
590
|
+
}, true);
|
|
591
|
+
}
|
|
592
|
+
init(issue) {
|
|
593
|
+
this.message = issue.message || this.constructor.name;
|
|
594
|
+
this.severity = issue.severity || "error";
|
|
595
|
+
this.system = issue.system;
|
|
596
|
+
this.code = issue.code;
|
|
597
|
+
this.details = issue.details;
|
|
598
|
+
}
|
|
599
|
+
initString(issue) {
|
|
600
|
+
this.message = String(issue || "") || this.constructor.name;
|
|
601
|
+
this.severity = "error";
|
|
602
|
+
this.code = this.constructor.name;
|
|
603
|
+
}
|
|
604
|
+
initError(issue) {
|
|
605
|
+
if (typeof issue.status === "number")
|
|
606
|
+
this.status = issue.status;
|
|
607
|
+
else if (typeof issue.getStatus === "function")
|
|
608
|
+
this.status = issue.getStatus();
|
|
609
|
+
this.message = issue.message;
|
|
610
|
+
this.severity = issue.severity || "error";
|
|
611
|
+
this.code = issue.code || issue.constructor.name;
|
|
598
612
|
}
|
|
599
613
|
};
|
|
600
614
|
|
|
@@ -607,10 +621,9 @@ var BadRequestError = class extends OpraException {
|
|
|
607
621
|
super(...arguments);
|
|
608
622
|
this.status = 400;
|
|
609
623
|
}
|
|
610
|
-
|
|
611
|
-
super.
|
|
624
|
+
init(issue) {
|
|
625
|
+
super.init({
|
|
612
626
|
message: translate("error:BAD_REQUEST", "Bad request"),
|
|
613
|
-
severity: "error",
|
|
614
627
|
code: "BAD_REQUEST",
|
|
615
628
|
...issue
|
|
616
629
|
});
|
|
@@ -626,10 +639,9 @@ var FailedDependencyError = class extends OpraException {
|
|
|
626
639
|
super(...arguments);
|
|
627
640
|
this.status = 424;
|
|
628
641
|
}
|
|
629
|
-
|
|
630
|
-
super.
|
|
642
|
+
init(issue) {
|
|
643
|
+
super.init({
|
|
631
644
|
message: translate("error:FAILED_DEPENDENCY", "The request failed due to failure of a previous request"),
|
|
632
|
-
severity: "error",
|
|
633
645
|
code: "FAILED_DEPENDENCY",
|
|
634
646
|
...issue
|
|
635
647
|
});
|
|
@@ -645,10 +657,9 @@ var ForbiddenError = class extends OpraException {
|
|
|
645
657
|
super(...arguments);
|
|
646
658
|
this.status = 403;
|
|
647
659
|
}
|
|
648
|
-
|
|
649
|
-
super.
|
|
660
|
+
init(issue) {
|
|
661
|
+
super.init({
|
|
650
662
|
message: translate("error:FORBIDDEN", "You are not authorized to perform this action"),
|
|
651
|
-
severity: "error",
|
|
652
663
|
code: "FORBIDDEN",
|
|
653
664
|
...issue
|
|
654
665
|
});
|
|
@@ -664,10 +675,9 @@ var MethodNotAllowedError = class extends OpraException {
|
|
|
664
675
|
super(...arguments);
|
|
665
676
|
this.status = 405;
|
|
666
677
|
}
|
|
667
|
-
|
|
668
|
-
super.
|
|
678
|
+
init(issue) {
|
|
679
|
+
super.init({
|
|
669
680
|
message: translate("error:METHOD_NOT_ALLOWED", "Method not allowed"),
|
|
670
|
-
severity: "error",
|
|
671
681
|
code: "METHOD_NOT_ALLOWED",
|
|
672
682
|
...issue
|
|
673
683
|
});
|
|
@@ -683,10 +693,9 @@ var NotAcceptableError = class extends OpraException {
|
|
|
683
693
|
super(...arguments);
|
|
684
694
|
this.status = 406;
|
|
685
695
|
}
|
|
686
|
-
|
|
687
|
-
super.
|
|
696
|
+
init(issue) {
|
|
697
|
+
super.init({
|
|
688
698
|
message: translate("error:NOT_ACCEPTABLE", "Not Acceptable"),
|
|
689
|
-
severity: "error",
|
|
690
699
|
code: "NOT_ACCEPTABLE",
|
|
691
700
|
...issue
|
|
692
701
|
});
|
|
@@ -702,10 +711,9 @@ var NotFoundError = class extends OpraException {
|
|
|
702
711
|
super(...arguments);
|
|
703
712
|
this.status = 404;
|
|
704
713
|
}
|
|
705
|
-
|
|
706
|
-
super.
|
|
714
|
+
init(issue) {
|
|
715
|
+
super.init({
|
|
707
716
|
message: translate("error:NOT_FOUND", "Not found"),
|
|
708
|
-
severity: "error",
|
|
709
717
|
code: "NOT_FOUND",
|
|
710
718
|
...issue
|
|
711
719
|
});
|
|
@@ -721,10 +729,9 @@ var UnauthorizedError = class extends OpraException {
|
|
|
721
729
|
super(...arguments);
|
|
722
730
|
this.status = 401;
|
|
723
731
|
}
|
|
724
|
-
|
|
725
|
-
super.
|
|
732
|
+
init(issue) {
|
|
733
|
+
super.init({
|
|
726
734
|
message: translate("error:UNAUTHORIZED", "You have not been authenticated to perform this action"),
|
|
727
|
-
severity: "error",
|
|
728
735
|
code: "UNAUTHORIZED",
|
|
729
736
|
...issue
|
|
730
737
|
});
|
|
@@ -740,8 +747,8 @@ var UnprocessableEntityError = class extends OpraException {
|
|
|
740
747
|
super(...arguments);
|
|
741
748
|
this.status = 422;
|
|
742
749
|
}
|
|
743
|
-
|
|
744
|
-
super.
|
|
750
|
+
init(issue) {
|
|
751
|
+
super.init({
|
|
745
752
|
message: translate("error:UNPROCESSABLE_ENTITY", "Unprocessable entity"),
|
|
746
753
|
severity: "error",
|
|
747
754
|
code: "UNPROCESSABLE_ENTITY",
|
|
@@ -751,33 +758,33 @@ var UnprocessableEntityError = class extends OpraException {
|
|
|
751
758
|
};
|
|
752
759
|
|
|
753
760
|
// ../../build/common/esm/exception/wrap-exception.js
|
|
754
|
-
function wrapException(
|
|
755
|
-
if (
|
|
756
|
-
return
|
|
761
|
+
function wrapException(error) {
|
|
762
|
+
if (error instanceof OpraException)
|
|
763
|
+
return error;
|
|
757
764
|
let status = 500;
|
|
758
|
-
if (typeof
|
|
759
|
-
status =
|
|
760
|
-
else if (typeof
|
|
761
|
-
status =
|
|
765
|
+
if (typeof error.status === "number")
|
|
766
|
+
status = error.status;
|
|
767
|
+
else if (typeof error.getStatus === "function")
|
|
768
|
+
status = error.getStatus();
|
|
762
769
|
switch (status) {
|
|
763
770
|
case 400:
|
|
764
|
-
return new BadRequestError(
|
|
771
|
+
return new BadRequestError(error);
|
|
765
772
|
case 401:
|
|
766
|
-
return new UnauthorizedError(
|
|
773
|
+
return new UnauthorizedError(error);
|
|
767
774
|
case 403:
|
|
768
|
-
return new ForbiddenError(
|
|
775
|
+
return new ForbiddenError(error);
|
|
769
776
|
case 404:
|
|
770
|
-
return new NotFoundError(
|
|
777
|
+
return new NotFoundError(error);
|
|
771
778
|
case 405:
|
|
772
|
-
return new MethodNotAllowedError(
|
|
779
|
+
return new MethodNotAllowedError(error);
|
|
773
780
|
case 406:
|
|
774
|
-
return new NotAcceptableError(
|
|
781
|
+
return new NotAcceptableError(error);
|
|
775
782
|
case 422:
|
|
776
|
-
return new UnprocessableEntityError(
|
|
783
|
+
return new UnprocessableEntityError(error);
|
|
777
784
|
case 424:
|
|
778
|
-
return new FailedDependencyError(
|
|
785
|
+
return new FailedDependencyError(error);
|
|
779
786
|
default:
|
|
780
|
-
return new FailedDependencyError(
|
|
787
|
+
return new FailedDependencyError(error);
|
|
781
788
|
}
|
|
782
789
|
}
|
|
783
790
|
__name(wrapException, "wrapException");
|
|
@@ -812,10 +819,9 @@ var InternalServerError = class extends OpraException {
|
|
|
812
819
|
super(...arguments);
|
|
813
820
|
this.status = 500;
|
|
814
821
|
}
|
|
815
|
-
|
|
816
|
-
super.
|
|
822
|
+
init(issue) {
|
|
823
|
+
super.init({
|
|
817
824
|
message: translate("error:INTERNAL_SERVER_ERROR", "Internal server error"),
|
|
818
|
-
severity: "error",
|
|
819
825
|
code: "INTERNAL_SERVER_ERROR",
|
|
820
826
|
...issue
|
|
821
827
|
});
|
|
@@ -855,8 +861,7 @@ var ResourceNotFoundError = class extends OpraException {
|
|
|
855
861
|
resource,
|
|
856
862
|
key: keyValue
|
|
857
863
|
}
|
|
858
|
-
}, cause);
|
|
859
|
-
this.status = 404;
|
|
864
|
+
}, cause, 404);
|
|
860
865
|
}
|
|
861
866
|
};
|
|
862
867
|
|
|
@@ -9726,7 +9731,7 @@ var UnionTypeClass = class extends DataType {
|
|
|
9726
9731
|
throw new TypeError(`${opra_schema_ns_exports.UnionType.Kind} shall contain ${opra_schema_ns_exports.ComplexType.Kind}, ${opra_schema_ns_exports.UnionType.Kind} of ${opra_schema_ns_exports.MappedType.Kind} types.`);
|
|
9727
9732
|
own.types.push(base);
|
|
9728
9733
|
if (base.additionalFields)
|
|
9729
|
-
this.additionalFields =
|
|
9734
|
+
this.additionalFields = base.additionalFields;
|
|
9730
9735
|
this.fields.setAll(base.fields);
|
|
9731
9736
|
}
|
|
9732
9737
|
this.types = [...own.types];
|
|
@@ -9799,7 +9804,7 @@ function _generateDecoder(type, codec, options) {
|
|
|
9799
9804
|
}
|
|
9800
9805
|
return vg3.isObject(schema, {
|
|
9801
9806
|
ctor: type.ctor,
|
|
9802
|
-
additionalFields: type.additionalFields ??
|
|
9807
|
+
additionalFields: type.additionalFields ?? false,
|
|
9803
9808
|
name: type.name,
|
|
9804
9809
|
caseInSensitive: true
|
|
9805
9810
|
});
|
|
@@ -23,7 +23,7 @@ class UnionTypeClass extends data_type_js_1.DataType {
|
|
|
23
23
|
`${index_js_2.OpraSchema.UnionType.Kind} of ${index_js_2.OpraSchema.MappedType.Kind} types.`);
|
|
24
24
|
own.types.push(base);
|
|
25
25
|
if (base.additionalFields)
|
|
26
|
-
this.additionalFields =
|
|
26
|
+
this.additionalFields = base.additionalFields;
|
|
27
27
|
this.fields.setAll(base.fields);
|
|
28
28
|
}
|
|
29
29
|
this.types = [...own.types];
|
|
@@ -31,7 +31,7 @@ function _generateDecoder(type, codec, options) {
|
|
|
31
31
|
}
|
|
32
32
|
return vg.isObject(schema, {
|
|
33
33
|
ctor: type.ctor,
|
|
34
|
-
additionalFields: type.additionalFields ??
|
|
34
|
+
additionalFields: type.additionalFields ?? false,
|
|
35
35
|
name: type.name,
|
|
36
36
|
caseInSensitive: true,
|
|
37
37
|
});
|
|
@@ -13,10 +13,9 @@ class BadRequestError extends opra_exception_js_1.OpraException {
|
|
|
13
13
|
super(...arguments);
|
|
14
14
|
this.status = 400;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
super.
|
|
16
|
+
init(issue) {
|
|
17
|
+
super.init({
|
|
18
18
|
message: (0, index_js_1.translate)('error:BAD_REQUEST', 'Bad request'),
|
|
19
|
-
severity: 'error',
|
|
20
19
|
code: 'BAD_REQUEST',
|
|
21
20
|
...issue
|
|
22
21
|
});
|
|
@@ -12,10 +12,9 @@ class FailedDependencyError extends opra_exception_js_1.OpraException {
|
|
|
12
12
|
super(...arguments);
|
|
13
13
|
this.status = 424;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
super.
|
|
15
|
+
init(issue) {
|
|
16
|
+
super.init({
|
|
17
17
|
message: (0, index_js_1.translate)('error:FAILED_DEPENDENCY', 'The request failed due to failure of a previous request'),
|
|
18
|
-
severity: 'error',
|
|
19
18
|
code: 'FAILED_DEPENDENCY',
|
|
20
19
|
...issue
|
|
21
20
|
});
|
|
@@ -14,10 +14,9 @@ class ForbiddenError extends opra_exception_js_1.OpraException {
|
|
|
14
14
|
super(...arguments);
|
|
15
15
|
this.status = 403;
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
super.
|
|
17
|
+
init(issue) {
|
|
18
|
+
super.init({
|
|
19
19
|
message: (0, index_js_1.translate)('error:FORBIDDEN', 'You are not authorized to perform this action'),
|
|
20
|
-
severity: 'error',
|
|
21
20
|
code: 'FORBIDDEN',
|
|
22
21
|
...issue
|
|
23
22
|
});
|
|
@@ -12,10 +12,9 @@ class InternalServerError extends opra_exception_js_1.OpraException {
|
|
|
12
12
|
super(...arguments);
|
|
13
13
|
this.status = 500;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
super.
|
|
15
|
+
init(issue) {
|
|
16
|
+
super.init({
|
|
17
17
|
message: (0, index_js_1.translate)('error:INTERNAL_SERVER_ERROR', 'Internal server error'),
|
|
18
|
-
severity: 'error',
|
|
19
18
|
code: 'INTERNAL_SERVER_ERROR',
|
|
20
19
|
...issue
|
|
21
20
|
});
|
|
@@ -13,10 +13,9 @@ class MethodNotAllowedError extends opra_exception_js_1.OpraException {
|
|
|
13
13
|
super(...arguments);
|
|
14
14
|
this.status = 405;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
super.
|
|
16
|
+
init(issue) {
|
|
17
|
+
super.init({
|
|
18
18
|
message: (0, index_js_1.translate)('error:METHOD_NOT_ALLOWED', 'Method not allowed'),
|
|
19
|
-
severity: 'error',
|
|
20
19
|
code: 'METHOD_NOT_ALLOWED',
|
|
21
20
|
...issue
|
|
22
21
|
});
|
|
@@ -13,10 +13,9 @@ class NotAcceptableError extends opra_exception_js_1.OpraException {
|
|
|
13
13
|
super(...arguments);
|
|
14
14
|
this.status = 406;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
super.
|
|
16
|
+
init(issue) {
|
|
17
|
+
super.init({
|
|
18
18
|
message: (0, index_js_1.translate)('error:NOT_ACCEPTABLE', 'Not Acceptable'),
|
|
19
|
-
severity: 'error',
|
|
20
19
|
code: 'NOT_ACCEPTABLE',
|
|
21
20
|
...issue
|
|
22
21
|
});
|
|
@@ -16,10 +16,9 @@ class NotFoundError extends opra_exception_js_1.OpraException {
|
|
|
16
16
|
super(...arguments);
|
|
17
17
|
this.status = 404;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
super.
|
|
19
|
+
init(issue) {
|
|
20
|
+
super.init({
|
|
21
21
|
message: (0, index_js_1.translate)('error:NOT_FOUND', 'Not found'),
|
|
22
|
-
severity: 'error',
|
|
23
22
|
code: 'NOT_FOUND',
|
|
24
23
|
...issue
|
|
25
24
|
});
|
|
@@ -13,10 +13,9 @@ class UnauthorizedError extends opra_exception_js_1.OpraException {
|
|
|
13
13
|
super(...arguments);
|
|
14
14
|
this.status = 401;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
super.
|
|
16
|
+
init(issue) {
|
|
17
|
+
super.init({
|
|
18
18
|
message: (0, index_js_1.translate)('error:UNAUTHORIZED', 'You have not been authenticated to perform this action'),
|
|
19
|
-
severity: 'error',
|
|
20
19
|
code: 'UNAUTHORIZED',
|
|
21
20
|
...issue
|
|
22
21
|
});
|
|
@@ -12,8 +12,8 @@ class UnprocessableEntityError extends opra_exception_js_1.OpraException {
|
|
|
12
12
|
super(...arguments);
|
|
13
13
|
this.status = 422;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
super.
|
|
15
|
+
init(issue) {
|
|
16
|
+
super.init({
|
|
17
17
|
message: (0, index_js_1.translate)('error:UNPROCESSABLE_ENTITY', 'Unprocessable entity'),
|
|
18
18
|
severity: 'error',
|
|
19
19
|
code: 'UNPROCESSABLE_ENTITY',
|
|
@@ -1,56 +1,71 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OpraException = void 0;
|
|
4
|
-
const index_js_1 = require("../
|
|
4
|
+
const index_js_1 = require("../helpers/index.js");
|
|
5
|
+
const index_js_2 = require("../i18n/index.js");
|
|
6
|
+
const inDevelopment = (process.env.NODE_ENV || '').startsWith('dev');
|
|
5
7
|
/**
|
|
6
8
|
* Defines the base Opra exception, which is handled by the default Exceptions Handler.
|
|
7
9
|
*/
|
|
8
10
|
class OpraException extends Error {
|
|
9
|
-
constructor(issue,
|
|
10
|
-
super('');
|
|
11
|
+
constructor(issue, arg1, arg2) {
|
|
12
|
+
super('Unknown error');
|
|
11
13
|
this.status = 500;
|
|
12
|
-
|
|
14
|
+
let cause = arg1 && arg1 instanceof Error ? arg1 : undefined;
|
|
15
|
+
this.status = (typeof arg1 === 'number' ? arg1 : Number(arg2)) || 500;
|
|
13
16
|
if (issue instanceof Error)
|
|
14
17
|
cause = issue;
|
|
15
|
-
|
|
18
|
+
// noinspection SuspiciousTypeOfGuard
|
|
19
|
+
if (cause && cause instanceof Error) {
|
|
16
20
|
this.cause = cause;
|
|
17
21
|
if (cause.stack)
|
|
18
22
|
this.stack = cause.stack;
|
|
19
23
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this._issue = {
|
|
28
|
-
message: 'Unknown error',
|
|
29
|
-
severity: 'error',
|
|
30
|
-
...issue,
|
|
31
|
-
};
|
|
24
|
+
if (typeof issue === 'string')
|
|
25
|
+
this.initString(issue);
|
|
26
|
+
else if (issue instanceof Error)
|
|
27
|
+
this.initError(issue);
|
|
28
|
+
else if (issue && typeof issue === 'object')
|
|
29
|
+
this.init(issue);
|
|
30
|
+
this.message = this.message || this.constructor.name;
|
|
32
31
|
}
|
|
33
32
|
setStatus(status) {
|
|
34
33
|
this.status = status;
|
|
35
34
|
return this;
|
|
36
35
|
}
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
toString() {
|
|
37
|
+
return index_js_2.i18n.deep(this.message);
|
|
39
38
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
39
|
+
toJSON() {
|
|
40
|
+
return (0, index_js_1.omitUndefined)({
|
|
41
|
+
message: this.message,
|
|
42
|
+
severity: this.severity,
|
|
43
|
+
system: this.system,
|
|
44
|
+
code: this.code,
|
|
45
|
+
details: this.details,
|
|
46
|
+
stack: inDevelopment ? this.stack?.split('\n') : undefined
|
|
47
|
+
}, true);
|
|
48
|
+
}
|
|
49
|
+
init(issue) {
|
|
50
|
+
this.message = issue.message || this.constructor.name;
|
|
51
|
+
this.severity = issue.severity || 'error';
|
|
52
|
+
this.system = issue.system;
|
|
53
|
+
this.code = issue.code;
|
|
54
|
+
this.details = issue.details;
|
|
55
|
+
}
|
|
56
|
+
initString(issue) {
|
|
57
|
+
this.message = String(issue || '') || this.constructor.name;
|
|
58
|
+
this.severity = 'error';
|
|
59
|
+
this.code = this.constructor.name;
|
|
60
|
+
}
|
|
61
|
+
initError(issue) {
|
|
62
|
+
if (typeof issue.status === 'number')
|
|
63
|
+
this.status = issue.status;
|
|
64
|
+
else if (typeof issue.getStatus === 'function')
|
|
65
|
+
this.status = issue.getStatus();
|
|
66
|
+
this.message = issue.message;
|
|
67
|
+
this.severity = issue.severity || 'error';
|
|
68
|
+
this.code = issue.code || (issue.constructor.name);
|
|
54
69
|
}
|
|
55
70
|
}
|
|
56
71
|
exports.OpraException = OpraException;
|
|
@@ -10,33 +10,33 @@ const not_found_error_js_1 = require("./http-errors/not-found.error.js");
|
|
|
10
10
|
const unauthorized_error_js_1 = require("./http-errors/unauthorized.error.js");
|
|
11
11
|
const unprocessable_entity_error_js_1 = require("./http-errors/unprocessable-entity.error.js");
|
|
12
12
|
const opra_exception_js_1 = require("./opra-exception.js");
|
|
13
|
-
function wrapException(
|
|
14
|
-
if (
|
|
15
|
-
return
|
|
13
|
+
function wrapException(error) {
|
|
14
|
+
if (error instanceof opra_exception_js_1.OpraException)
|
|
15
|
+
return error;
|
|
16
16
|
let status = 500;
|
|
17
|
-
if (typeof
|
|
18
|
-
status =
|
|
19
|
-
else if (typeof
|
|
20
|
-
status =
|
|
17
|
+
if (typeof error.status === 'number')
|
|
18
|
+
status = error.status;
|
|
19
|
+
else if (typeof error.getStatus === 'function')
|
|
20
|
+
status = error.getStatus();
|
|
21
21
|
switch (status) {
|
|
22
22
|
case 400:
|
|
23
|
-
return new bad_request_error_js_1.BadRequestError(
|
|
23
|
+
return new bad_request_error_js_1.BadRequestError(error);
|
|
24
24
|
case 401:
|
|
25
|
-
return new unauthorized_error_js_1.UnauthorizedError(
|
|
25
|
+
return new unauthorized_error_js_1.UnauthorizedError(error);
|
|
26
26
|
case 403:
|
|
27
|
-
return new forbidden_error_js_1.ForbiddenError(
|
|
27
|
+
return new forbidden_error_js_1.ForbiddenError(error);
|
|
28
28
|
case 404:
|
|
29
|
-
return new not_found_error_js_1.NotFoundError(
|
|
29
|
+
return new not_found_error_js_1.NotFoundError(error);
|
|
30
30
|
case 405:
|
|
31
|
-
return new method_not_allowed_error_js_1.MethodNotAllowedError(
|
|
31
|
+
return new method_not_allowed_error_js_1.MethodNotAllowedError(error);
|
|
32
32
|
case 406:
|
|
33
|
-
return new not_acceptable_error_js_1.NotAcceptableError(
|
|
33
|
+
return new not_acceptable_error_js_1.NotAcceptableError(error);
|
|
34
34
|
case 422:
|
|
35
|
-
return new unprocessable_entity_error_js_1.UnprocessableEntityError(
|
|
35
|
+
return new unprocessable_entity_error_js_1.UnprocessableEntityError(error);
|
|
36
36
|
case 424:
|
|
37
|
-
return new failed_dependency_error_js_1.FailedDependencyError(
|
|
37
|
+
return new failed_dependency_error_js_1.FailedDependencyError(error);
|
|
38
38
|
default:
|
|
39
|
-
return new failed_dependency_error_js_1.FailedDependencyError(
|
|
39
|
+
return new failed_dependency_error_js_1.FailedDependencyError(error);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
exports.wrapException = wrapException;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isAbsoluteUrl = exports.isUrlString = void 0;
|
|
4
|
-
const url_1 = require("url");
|
|
5
4
|
const URL_PATTERN = /^(https?:\/\/.)[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)$/i;
|
|
6
5
|
function isUrlString(url) {
|
|
7
6
|
return URL_PATTERN.test(url);
|
|
@@ -9,6 +8,6 @@ function isUrlString(url) {
|
|
|
9
8
|
exports.isUrlString = isUrlString;
|
|
10
9
|
const isAbsoluteUrl = (urlString) => {
|
|
11
10
|
return !urlString.includes('://') &&
|
|
12
|
-
(new
|
|
11
|
+
(new URL(urlString, 'http://tempuri.org/')).host !== 'tempuri.org';
|
|
13
12
|
};
|
|
14
13
|
exports.isAbsoluteUrl = isAbsoluteUrl;
|
|
@@ -19,7 +19,7 @@ class UnionTypeClass extends DataType {
|
|
|
19
19
|
`${OpraSchema.UnionType.Kind} of ${OpraSchema.MappedType.Kind} types.`);
|
|
20
20
|
own.types.push(base);
|
|
21
21
|
if (base.additionalFields)
|
|
22
|
-
this.additionalFields =
|
|
22
|
+
this.additionalFields = base.additionalFields;
|
|
23
23
|
this.fields.setAll(base.fields);
|
|
24
24
|
}
|
|
25
25
|
this.types = [...own.types];
|