response-standardizer 1.1.9 → 1.2.0
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/index.d.ts +1 -1
- package/dist/index.js +8 -8
- package/package.json +1 -1
- package/src/index.ts +10 -10
package/dist/index.d.ts
CHANGED
|
@@ -24,4 +24,4 @@ export declare const warn: (message: string, meta?: any) => void;
|
|
|
24
24
|
export declare const info: (message: string, meta?: any) => void;
|
|
25
25
|
export declare const log: (level: "INFO" | "WARN" | "ERROR", message: string, meta?: any) => void;
|
|
26
26
|
export declare const handleRestException: (req: Request, res: Response, err: Error) => void;
|
|
27
|
-
export declare const handleValidationException: (error: any) =>
|
|
27
|
+
export declare const handleValidationException: (error: any) => never;
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,6 @@ import { generateRequestId, getTimestamp } from "./utils.js";
|
|
|
2
2
|
import axios from "axios";
|
|
3
3
|
import jwt from "jsonwebtoken";
|
|
4
4
|
import path from "path";
|
|
5
|
-
import { ZodError } from "zod";
|
|
6
5
|
import { ServiceException } from "./service.exception.js";
|
|
7
6
|
let KEYCLOAK_PUBLIC_KEY = null;
|
|
8
7
|
export const initKeycloak = async (config) => {
|
|
@@ -191,15 +190,16 @@ export const handleRestException = (req, res, err) => {
|
|
|
191
190
|
}
|
|
192
191
|
};
|
|
193
192
|
export const handleValidationException = (error) => {
|
|
194
|
-
|
|
193
|
+
const zodError = error;
|
|
194
|
+
if (zodError.issues) {
|
|
195
195
|
const validationErrors = {};
|
|
196
|
-
|
|
197
|
-
const
|
|
198
|
-
if (!validationErrors[
|
|
199
|
-
validationErrors[
|
|
200
|
-
|
|
201
|
-
validationErrors[field].push(issue.message);
|
|
196
|
+
zodError.issues.forEach((i) => {
|
|
197
|
+
const key = i.path[0];
|
|
198
|
+
if (!validationErrors[key])
|
|
199
|
+
validationErrors[key] = [];
|
|
200
|
+
validationErrors[key].push(i.message);
|
|
202
201
|
});
|
|
203
202
|
throw new ServiceException("Validation error", 400, validationErrors);
|
|
204
203
|
}
|
|
204
|
+
throw new ServiceException("Internal server error", 500, error);
|
|
205
205
|
};
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -248,15 +248,15 @@ export const handleRestException = (req: Request, res: Response, err: Error) =>
|
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
export const handleValidationException = (error: any) => {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
throw new ServiceException("Validation error", 400, validationErrors);
|
|
251
|
+
const zodError = error as ZodError;
|
|
252
|
+
if (zodError.issues) {
|
|
253
|
+
const validationErrors: any = {};
|
|
254
|
+
zodError.issues.forEach((i) => {
|
|
255
|
+
const key = i.path[0];
|
|
256
|
+
if (!validationErrors[key]) validationErrors[key] = [];
|
|
257
|
+
validationErrors[key].push(i.message);
|
|
258
|
+
});
|
|
259
|
+
throw new ServiceException("Validation error", 400, validationErrors);
|
|
261
260
|
}
|
|
261
|
+
throw new ServiceException("Internal server error", 500, error);
|
|
262
262
|
}
|