@lucaapp/service-utils 1.53.0 → 1.53.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/dist/lib/api/endpoint.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.mountEndpoint = void 0;
|
|
|
7
7
|
const zod_1 = require("zod");
|
|
8
8
|
const assert_1 = __importDefault(require("assert"));
|
|
9
9
|
const http_1 = require("./types/http");
|
|
10
|
+
const libphonenumber_js_1 = require("libphonenumber-js");
|
|
10
11
|
const sendBadContextError = (response, error, debug) => {
|
|
11
12
|
response.err = error;
|
|
12
13
|
return response.status(500).send({
|
|
@@ -37,7 +38,7 @@ const sendBadResponseError = (response, error, debug) => {
|
|
|
37
38
|
}),
|
|
38
39
|
});
|
|
39
40
|
};
|
|
40
|
-
const
|
|
41
|
+
const sendBadRequestZodError = (response, error) => {
|
|
41
42
|
response.err = error;
|
|
42
43
|
return response.status(400).send({
|
|
43
44
|
error: http_1.HTTPStatus.BAD_REQUEST,
|
|
@@ -45,6 +46,13 @@ const sendBadRequestError = (response, error) => {
|
|
|
45
46
|
issues: error.issues,
|
|
46
47
|
});
|
|
47
48
|
};
|
|
49
|
+
const sendBadRequestError = (response, error) => {
|
|
50
|
+
response.err = error;
|
|
51
|
+
return response.status(400).send({
|
|
52
|
+
error: http_1.HTTPStatus.BAD_REQUEST,
|
|
53
|
+
message: error.message,
|
|
54
|
+
});
|
|
55
|
+
};
|
|
48
56
|
const sendKnownErrorResponse = (response, statusCode, error, debug) => {
|
|
49
57
|
response.err = error;
|
|
50
58
|
response.status(statusCode).send({
|
|
@@ -155,7 +163,7 @@ new Promise(async (resolve) => {
|
|
|
155
163
|
}
|
|
156
164
|
catch (error) {
|
|
157
165
|
if (error instanceof zod_1.ZodError) {
|
|
158
|
-
|
|
166
|
+
sendBadRequestZodError(response, error);
|
|
159
167
|
return resolve(false);
|
|
160
168
|
}
|
|
161
169
|
throw error;
|
|
@@ -213,7 +221,11 @@ const mountEndpoint = (router, method, path, options, handler, debug) => {
|
|
|
213
221
|
}
|
|
214
222
|
catch (error) {
|
|
215
223
|
if (error instanceof zod_1.ZodError) {
|
|
216
|
-
return
|
|
224
|
+
return sendBadRequestZodError(response, error);
|
|
225
|
+
}
|
|
226
|
+
if (error instanceof libphonenumber_js_1.ParseError) {
|
|
227
|
+
const newError = new Error(error.message);
|
|
228
|
+
return sendBadRequestError(response, newError);
|
|
217
229
|
}
|
|
218
230
|
throw error;
|
|
219
231
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lucaapp/service-utils",
|
|
3
|
-
"version": "1.53.
|
|
3
|
+
"version": "1.53.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"express-async-errors": "3.1.1",
|
|
33
33
|
"jose": "4.9.2",
|
|
34
34
|
"kafkajs": "2.1.0",
|
|
35
|
+
"libphonenumber-js": "1.9.44",
|
|
35
36
|
"lodash": "^4.17.21",
|
|
36
37
|
"moment": "2.29.4",
|
|
37
38
|
"moment-timezone": "^0.5.43",
|