response-standardizer 1.2.8 → 1.2.9

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 CHANGED
@@ -25,8 +25,7 @@ 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
27
  export declare const handleRestResponse: (req: Request, res: Response, response: ServiceResponse) => void;
28
- export declare const getValidationErrors: (error: any) => ServiceResponse | undefined;
29
- export declare const handleServiceException: (message: string, err: any) => ServiceResponse | undefined;
28
+ export declare const handleServiceException: (message: string, err: any) => ServiceResponse;
30
29
  export declare const handleValidationException: (error: any) => never;
31
30
  export declare class ServiceException extends Error {
32
31
  status: number;
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ServiceResponse = exports.ServiceException = exports.handleValidationException = exports.handleServiceException = exports.getValidationErrors = exports.handleRestResponse = exports.handleRestException = exports.log = exports.info = exports.warn = exports.error = exports.RestMiddleware = exports.RestResponse = exports.protect = exports.initKeycloak = void 0;
6
+ exports.ServiceResponse = exports.ServiceException = exports.handleValidationException = exports.handleServiceException = exports.handleRestResponse = exports.handleRestException = exports.log = exports.info = exports.warn = exports.error = exports.RestMiddleware = exports.RestResponse = exports.protect = exports.initKeycloak = void 0;
7
7
  const utils_1 = require("./utils");
8
8
  const axios_1 = __importDefault(require("axios"));
9
9
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
@@ -223,23 +223,19 @@ const handleRestResponse = (req, res, response) => {
223
223
  return exports.RestResponse.exceptionError(req, res, response.message);
224
224
  };
225
225
  exports.handleRestResponse = handleRestResponse;
226
- const getValidationErrors = (error) => {
227
- const zodError = error;
228
- if (zodError.issues) {
229
- const validationErrors = {};
230
- zodError.issues.forEach((i) => {
231
- const key = i.path[0];
232
- if (!validationErrors[key])
233
- validationErrors[key] = [];
234
- validationErrors[key].push(i.message);
235
- });
236
- return new ServiceResponse(400, "Validation error", validationErrors);
237
- }
238
- };
239
- exports.getValidationErrors = getValidationErrors;
240
226
  const handleServiceException = (message, err) => {
241
227
  if (err instanceof zod_1.ZodError) {
242
- return (0, exports.getValidationErrors)(err);
228
+ const zodError = err;
229
+ if (zodError.issues) {
230
+ const validationErrors = {};
231
+ zodError.issues.forEach((i) => {
232
+ const key = i.path[0];
233
+ if (!validationErrors[key])
234
+ validationErrors[key] = [];
235
+ validationErrors[key].push(i.message);
236
+ });
237
+ return new ServiceResponse(400, "Validation error", validationErrors);
238
+ }
243
239
  }
244
240
  else if (err?.isAxiosError && err?.response && err.response.status) {
245
241
  (0, exports.error)(message, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "response-standardizer",
3
- "version": "1.2.8",
3
+ "version": "1.2.9",
4
4
  "description": "Express middleware to standardize API responses",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -262,21 +262,18 @@ export const handleRestResponse = (req: Request, res: Response, response: Servic
262
262
  }
263
263
  return RestResponse.exceptionError(req, res, response.message)
264
264
  }
265
- export const getValidationErrors = (error: any) : ServiceResponse | undefined => {
266
- const zodError = error as ZodError;
267
- if (zodError.issues) {
268
- const validationErrors: any = {};
269
- zodError.issues.forEach((i) => {
270
- const key = i.path[0];
271
- if (!validationErrors[key]) validationErrors[key] = [];
272
- validationErrors[key].push(i.message);
273
- });
274
- return new ServiceResponse(400, "Validation error", validationErrors)
275
- }
276
- }
277
- export const handleServiceException = (message: string, err: any) : ServiceResponse | undefined => {
265
+ export const handleServiceException = (message: string, err: any) : ServiceResponse => {
278
266
  if(err instanceof ZodError){
279
- return getValidationErrors(err)
267
+ const zodError = err as ZodError;
268
+ if (zodError.issues) {
269
+ const validationErrors: any = {};
270
+ zodError.issues.forEach((i) => {
271
+ const key = i.path[0];
272
+ if (!validationErrors[key]) validationErrors[key] = [];
273
+ validationErrors[key].push(i.message);
274
+ });
275
+ return new ServiceResponse(400, "Validation error", validationErrors)
276
+ }
280
277
  }else if((err as any)?.isAxiosError && (err as any)?.response && (err as any).response.status){
281
278
  error(message, {
282
279
  status: (err as any).response.status,