@nr1e/commons 0.0.2-alpha.10 → 0.0.2-alpha.11
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.js +26 -15
- package/errors/errors.js.map +1 -1
- package/package.json +1 -1
package/errors/errors.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
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
|
+
}
|
|
5
8
|
/**
|
|
6
9
|
* Checks if the given parameter is a NotFoundError.
|
|
7
10
|
*
|
|
@@ -20,9 +23,10 @@ exports.isNotFoundError = isNotFoundError;
|
|
|
20
23
|
*/
|
|
21
24
|
class NotFoundError extends Error {
|
|
22
25
|
constructor(message) {
|
|
23
|
-
|
|
26
|
+
message = message !== null && message !== void 0 ? message : 'Not found';
|
|
27
|
+
super(message);
|
|
24
28
|
this.statusCode = http_1.HttpStatusCode.NOT_FOUND;
|
|
25
|
-
this.body = message;
|
|
29
|
+
this.body = messageToJson(message);
|
|
26
30
|
this.name = 'NotFoundError';
|
|
27
31
|
}
|
|
28
32
|
}
|
|
@@ -45,9 +49,10 @@ exports.isForbiddenError = isForbiddenError;
|
|
|
45
49
|
*/
|
|
46
50
|
class ForbiddenError extends Error {
|
|
47
51
|
constructor(message) {
|
|
48
|
-
|
|
52
|
+
message = message !== null && message !== void 0 ? message : 'Forbidden';
|
|
53
|
+
super(message);
|
|
49
54
|
this.statusCode = http_1.HttpStatusCode.FORBIDDEN;
|
|
50
|
-
this.body = message;
|
|
55
|
+
this.body = messageToJson(message);
|
|
51
56
|
this.name = 'ForbiddenError';
|
|
52
57
|
}
|
|
53
58
|
}
|
|
@@ -66,9 +71,10 @@ exports.isValidationError = isValidationError;
|
|
|
66
71
|
*/
|
|
67
72
|
class ValidationError extends Error {
|
|
68
73
|
constructor(message) {
|
|
69
|
-
|
|
74
|
+
message = message !== null && message !== void 0 ? message : 'Validation error';
|
|
75
|
+
super(message);
|
|
70
76
|
this.statusCode = http_1.HttpStatusCode.BAD_REQUEST;
|
|
71
|
-
this.body = message;
|
|
77
|
+
this.body = messageToJson(message);
|
|
72
78
|
this.name = 'ValidationError';
|
|
73
79
|
}
|
|
74
80
|
}
|
|
@@ -87,9 +93,10 @@ exports.isBadRequestError = isBadRequestError;
|
|
|
87
93
|
*/
|
|
88
94
|
class BadRequestError extends Error {
|
|
89
95
|
constructor(message) {
|
|
96
|
+
message = message !== null && message !== void 0 ? message : 'Bad request';
|
|
90
97
|
super(message !== null && message !== void 0 ? message : 'Bad request');
|
|
91
98
|
this.statusCode = http_1.HttpStatusCode.BAD_REQUEST;
|
|
92
|
-
this.body = message;
|
|
99
|
+
this.body = messageToJson(message);
|
|
93
100
|
this.name = 'BadRequestError';
|
|
94
101
|
}
|
|
95
102
|
}
|
|
@@ -108,9 +115,10 @@ exports.isInternalServerError = isInternalServerError;
|
|
|
108
115
|
*/
|
|
109
116
|
class InternalServerError extends Error {
|
|
110
117
|
constructor(message) {
|
|
111
|
-
|
|
118
|
+
message = message !== null && message !== void 0 ? message : 'Internal server error';
|
|
119
|
+
super(message);
|
|
112
120
|
this.statusCode = http_1.HttpStatusCode.INTERNAL_SERVER_ERROR;
|
|
113
|
-
this.body = message;
|
|
121
|
+
this.body = messageToJson(message);
|
|
114
122
|
this.name = 'InternalServerError';
|
|
115
123
|
}
|
|
116
124
|
}
|
|
@@ -129,9 +137,10 @@ exports.isConflictError = isConflictError;
|
|
|
129
137
|
*/
|
|
130
138
|
class ConflictError extends Error {
|
|
131
139
|
constructor(message) {
|
|
132
|
-
|
|
140
|
+
message = message !== null && message !== void 0 ? message : 'Conflict';
|
|
141
|
+
super(message);
|
|
133
142
|
this.statusCode = http_1.HttpStatusCode.CONFLICT;
|
|
134
|
-
this.body = message;
|
|
143
|
+
this.body = messageToJson(message);
|
|
135
144
|
this.name = 'ConflictError';
|
|
136
145
|
}
|
|
137
146
|
}
|
|
@@ -153,9 +162,10 @@ exports.isUnsupportedMediaTypeError = isUnsupportedMediaTypeError;
|
|
|
153
162
|
*/
|
|
154
163
|
class UnsupportedMediaTypeError extends Error {
|
|
155
164
|
constructor(message) {
|
|
156
|
-
|
|
165
|
+
message = message !== null && message !== void 0 ? message : 'Unsupported media type';
|
|
166
|
+
super(message);
|
|
157
167
|
this.statusCode = http_1.HttpStatusCode.UNSUPPORTED_MEDIA_TYPE;
|
|
158
|
-
this.body = message;
|
|
168
|
+
this.body = messageToJson(message);
|
|
159
169
|
this.name = 'UnsupportedMediaTypeError';
|
|
160
170
|
}
|
|
161
171
|
}
|
|
@@ -174,10 +184,11 @@ exports.isNotImplementedError = isNotImplementedError;
|
|
|
174
184
|
*/
|
|
175
185
|
class NotImplementedError extends Error {
|
|
176
186
|
constructor(message) {
|
|
177
|
-
|
|
187
|
+
message = message !== null && message !== void 0 ? message : 'Not implemented';
|
|
188
|
+
super(message);
|
|
178
189
|
this.statusCode = http_1.HttpStatusCode.NOT_IMPLEMENTED;
|
|
179
190
|
this.expose = true;
|
|
180
|
-
this.body = message;
|
|
191
|
+
this.body = messageToJson(message);
|
|
181
192
|
this.name = 'NotImplementedError';
|
|
182
193
|
}
|
|
183
194
|
}
|
package/errors/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["errors.ts"],"names":[],"mappings":";;;AAAA,kCAAuC;AAQvC;;;;GAIG;AACH,SAAgB,eAAe,CAAC,CAAiB;IAC/C,OAAO,CAAC,CA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