@nr1e/commons 0.0.2-alpha.11 → 0.0.2-alpha.12
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/errors/errors.d.ts +11 -8
- package/errors/errors.js +8 -11
- package/errors/errors.js.map +1 -1
- package/package.json +1 -1
package/errors/errors.d.ts
CHANGED
|
@@ -4,6 +4,9 @@ interface IError {
|
|
|
4
4
|
name?: string;
|
|
5
5
|
statusCode?: HttpStatusCode | number;
|
|
6
6
|
}
|
|
7
|
+
export interface ErrorBody {
|
|
8
|
+
message: string;
|
|
9
|
+
}
|
|
7
10
|
/**
|
|
8
11
|
* Checks if the given parameter is a NotFoundError.
|
|
9
12
|
*
|
|
@@ -15,7 +18,7 @@ export declare function isNotFoundError(e?: IError | null): e is NotFoundError;
|
|
|
15
18
|
*/
|
|
16
19
|
export declare class NotFoundError extends Error {
|
|
17
20
|
readonly statusCode = HttpStatusCode.NOT_FOUND;
|
|
18
|
-
readonly body:
|
|
21
|
+
readonly body: ErrorBody | undefined;
|
|
19
22
|
constructor(message?: string);
|
|
20
23
|
}
|
|
21
24
|
/**
|
|
@@ -29,7 +32,7 @@ export declare function isForbiddenError(e?: IError | null): e is ForbiddenError
|
|
|
29
32
|
*/
|
|
30
33
|
export declare class ForbiddenError extends Error {
|
|
31
34
|
readonly statusCode = HttpStatusCode.FORBIDDEN;
|
|
32
|
-
readonly body:
|
|
35
|
+
readonly body: ErrorBody | undefined;
|
|
33
36
|
constructor(message?: string);
|
|
34
37
|
}
|
|
35
38
|
/**
|
|
@@ -43,7 +46,7 @@ export declare function isValidationError(e?: IError | null): e is ValidationErr
|
|
|
43
46
|
*/
|
|
44
47
|
export declare class ValidationError extends Error {
|
|
45
48
|
readonly statusCode = HttpStatusCode.BAD_REQUEST;
|
|
46
|
-
readonly body:
|
|
49
|
+
readonly body: ErrorBody | undefined;
|
|
47
50
|
constructor(message?: string);
|
|
48
51
|
}
|
|
49
52
|
/**
|
|
@@ -57,7 +60,7 @@ export declare function isBadRequestError(e?: IError | null): e is BadRequestErr
|
|
|
57
60
|
*/
|
|
58
61
|
export declare class BadRequestError extends Error {
|
|
59
62
|
readonly statusCode = HttpStatusCode.BAD_REQUEST;
|
|
60
|
-
readonly body:
|
|
63
|
+
readonly body: ErrorBody | undefined;
|
|
61
64
|
constructor(message?: string);
|
|
62
65
|
}
|
|
63
66
|
/**
|
|
@@ -71,7 +74,7 @@ export declare function isInternalServerError(e?: IError | null): e is InternalS
|
|
|
71
74
|
*/
|
|
72
75
|
export declare class InternalServerError extends Error {
|
|
73
76
|
readonly statusCode = HttpStatusCode.INTERNAL_SERVER_ERROR;
|
|
74
|
-
readonly body:
|
|
77
|
+
readonly body: ErrorBody | undefined;
|
|
75
78
|
constructor(message?: string);
|
|
76
79
|
}
|
|
77
80
|
/**
|
|
@@ -85,7 +88,7 @@ export declare function isConflictError(e?: IError | null): e is ConflictError;
|
|
|
85
88
|
*/
|
|
86
89
|
export declare class ConflictError extends Error {
|
|
87
90
|
readonly statusCode = HttpStatusCode.CONFLICT;
|
|
88
|
-
readonly body:
|
|
91
|
+
readonly body: ErrorBody | undefined;
|
|
89
92
|
constructor(message?: string);
|
|
90
93
|
}
|
|
91
94
|
/**
|
|
@@ -99,7 +102,7 @@ export declare function isUnsupportedMediaTypeError(e?: IError | null): e is Uns
|
|
|
99
102
|
*/
|
|
100
103
|
export declare class UnsupportedMediaTypeError extends Error {
|
|
101
104
|
readonly statusCode = HttpStatusCode.UNSUPPORTED_MEDIA_TYPE;
|
|
102
|
-
readonly body:
|
|
105
|
+
readonly body: ErrorBody | undefined;
|
|
103
106
|
constructor(message?: string);
|
|
104
107
|
}
|
|
105
108
|
/**
|
|
@@ -113,7 +116,7 @@ export declare function isNotImplementedError(e?: IError | null): e is NotImplem
|
|
|
113
116
|
*/
|
|
114
117
|
export declare class NotImplementedError extends Error {
|
|
115
118
|
readonly statusCode = HttpStatusCode.NOT_IMPLEMENTED;
|
|
116
|
-
readonly body:
|
|
119
|
+
readonly body: ErrorBody | undefined;
|
|
117
120
|
readonly expose = true;
|
|
118
121
|
constructor(message?: string);
|
|
119
122
|
}
|
package/errors/errors.js
CHANGED
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NotImplementedError = exports.isNotImplementedError = exports.UnsupportedMediaTypeError = exports.isUnsupportedMediaTypeError = exports.ConflictError = exports.isConflictError = exports.InternalServerError = exports.isInternalServerError = exports.BadRequestError = exports.isBadRequestError = exports.ValidationError = exports.isValidationError = exports.ForbiddenError = exports.isForbiddenError = exports.NotFoundError = exports.isNotFoundError = void 0;
|
|
4
4
|
const http_1 = require("../http");
|
|
5
|
-
function messageToJson(message) {
|
|
6
|
-
return JSON.stringify({ message });
|
|
7
|
-
}
|
|
8
5
|
/**
|
|
9
6
|
* Checks if the given parameter is a NotFoundError.
|
|
10
7
|
*
|
|
@@ -26,7 +23,7 @@ class NotFoundError extends Error {
|
|
|
26
23
|
message = message !== null && message !== void 0 ? message : 'Not found';
|
|
27
24
|
super(message);
|
|
28
25
|
this.statusCode = http_1.HttpStatusCode.NOT_FOUND;
|
|
29
|
-
this.body =
|
|
26
|
+
this.body = { message };
|
|
30
27
|
this.name = 'NotFoundError';
|
|
31
28
|
}
|
|
32
29
|
}
|
|
@@ -52,7 +49,7 @@ class ForbiddenError extends Error {
|
|
|
52
49
|
message = message !== null && message !== void 0 ? message : 'Forbidden';
|
|
53
50
|
super(message);
|
|
54
51
|
this.statusCode = http_1.HttpStatusCode.FORBIDDEN;
|
|
55
|
-
this.body =
|
|
52
|
+
this.body = { message };
|
|
56
53
|
this.name = 'ForbiddenError';
|
|
57
54
|
}
|
|
58
55
|
}
|
|
@@ -74,7 +71,7 @@ class ValidationError extends Error {
|
|
|
74
71
|
message = message !== null && message !== void 0 ? message : 'Validation error';
|
|
75
72
|
super(message);
|
|
76
73
|
this.statusCode = http_1.HttpStatusCode.BAD_REQUEST;
|
|
77
|
-
this.body =
|
|
74
|
+
this.body = { message };
|
|
78
75
|
this.name = 'ValidationError';
|
|
79
76
|
}
|
|
80
77
|
}
|
|
@@ -96,7 +93,7 @@ class BadRequestError extends Error {
|
|
|
96
93
|
message = message !== null && message !== void 0 ? message : 'Bad request';
|
|
97
94
|
super(message !== null && message !== void 0 ? message : 'Bad request');
|
|
98
95
|
this.statusCode = http_1.HttpStatusCode.BAD_REQUEST;
|
|
99
|
-
this.body =
|
|
96
|
+
this.body = { message };
|
|
100
97
|
this.name = 'BadRequestError';
|
|
101
98
|
}
|
|
102
99
|
}
|
|
@@ -118,7 +115,7 @@ class InternalServerError extends Error {
|
|
|
118
115
|
message = message !== null && message !== void 0 ? message : 'Internal server error';
|
|
119
116
|
super(message);
|
|
120
117
|
this.statusCode = http_1.HttpStatusCode.INTERNAL_SERVER_ERROR;
|
|
121
|
-
this.body =
|
|
118
|
+
this.body = { message };
|
|
122
119
|
this.name = 'InternalServerError';
|
|
123
120
|
}
|
|
124
121
|
}
|
|
@@ -140,7 +137,7 @@ class ConflictError extends Error {
|
|
|
140
137
|
message = message !== null && message !== void 0 ? message : 'Conflict';
|
|
141
138
|
super(message);
|
|
142
139
|
this.statusCode = http_1.HttpStatusCode.CONFLICT;
|
|
143
|
-
this.body =
|
|
140
|
+
this.body = { message };
|
|
144
141
|
this.name = 'ConflictError';
|
|
145
142
|
}
|
|
146
143
|
}
|
|
@@ -165,7 +162,7 @@ class UnsupportedMediaTypeError extends Error {
|
|
|
165
162
|
message = message !== null && message !== void 0 ? message : 'Unsupported media type';
|
|
166
163
|
super(message);
|
|
167
164
|
this.statusCode = http_1.HttpStatusCode.UNSUPPORTED_MEDIA_TYPE;
|
|
168
|
-
this.body =
|
|
165
|
+
this.body = { message };
|
|
169
166
|
this.name = 'UnsupportedMediaTypeError';
|
|
170
167
|
}
|
|
171
168
|
}
|
|
@@ -188,7 +185,7 @@ class NotImplementedError extends Error {
|
|
|
188
185
|
super(message);
|
|
189
186
|
this.statusCode = http_1.HttpStatusCode.NOT_IMPLEMENTED;
|
|
190
187
|
this.expose = true;
|
|
191
|
-
this.body =
|
|
188
|
+
this.body = { message };
|
|
192
189
|
this.name = 'NotImplementedError';
|
|
193
190
|
}
|
|
194
191
|
}
|
package/errors/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["errors.ts"],"names":[],"mappings":";;;AAAA,kCAAuC;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["errors.ts"],"names":[],"mappings":";;;AAAA,kCAAuC;AAYvC;;;;GAIG;AACH,SAAgB,eAAe,CAAC,CAAiB;IAC/C,OAAO,CAAC,CAAC,CACP,CAAC;QACD,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,UAAU;QACZ,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,IAAI,KAAK,eAAe,CAC3B,CAAC;AACJ,CAAC;AARD,0CAQC;AAED;;GAEG;AACH,MAAa,aAAc,SAAQ,KAAK;IAGtC,YAAY,OAAgB;QAC1B,OAAO,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,WAAW,CAAC;QACjC,KAAK,CAAC,OAAO,CAAC,CAAC;QAJR,eAAU,GAAG,qBAAc,CAAC,SAAS,CAAC;QAK7C,IAAI,CAAC,IAAI,GAAG,EAAC,OAAO,EAAC,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AATD,sCASC;AAED;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,CAAiB;IAChD,OAAO,CAAC,CAAC,CACP,CAAC;QACD,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,UAAU;QACZ,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,IAAI,KAAK,gBAAgB,CAC5B,CAAC;AACJ,CAAC;AARD,4CAQC;AAED;;GAEG;AACH,MAAa,cAAe,SAAQ,KAAK;IAGvC,YAAY,OAAgB;QA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