response-standardizer 1.2.4 → 1.2.5

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.js CHANGED
@@ -209,8 +209,8 @@ const handleRestResponse = (req, res, response) => {
209
209
  else if (response?.code === 403) {
210
210
  exports.RestResponse.accessDenied(req, res, response?.message);
211
211
  }
212
- else if (response?.code === 400 && response.errors) {
213
- exports.RestResponse.validationError(req, res, response.errors);
212
+ else if (response?.code === 400) {
213
+ exports.RestResponse.validationError(req, res, response?.errors);
214
214
  }
215
215
  else if (response?.code === 500) {
216
216
  exports.RestResponse.exceptionError(req, res, response.message);
package/dist/types.d.ts CHANGED
@@ -21,7 +21,7 @@ export interface Pagination<T> {
21
21
  export interface ServiceResponse {
22
22
  code: number;
23
23
  message: string;
24
- errors: Record<string, string[]> | null;
24
+ errors?: ErrorFields;
25
25
  }
26
26
  export type ErrorFields = Record<string, string[]>;
27
27
  export type Middleware = (req: Request, res: Response, next: NextFunction) => void;
@@ -33,7 +33,7 @@ export interface RestResponseFunctions {
33
33
  paginate: <T>(req: Request, res: Response, data: Pagination<T>) => void;
34
34
  created: <T>(req: Request, res: Response, data: T) => void;
35
35
  deleted: (req: Request, res: Response) => void;
36
- validationError: (req: Request, res: Response, errors: ErrorFields, message?: string) => void;
36
+ validationError: (req: Request, res: Response, errors?: ErrorFields, message?: string) => void;
37
37
  exceptionError: (req: Request, res: Response, errors: any, message?: string) => void;
38
38
  unauthorized: (req: Request, res: Response, message?: string) => void;
39
39
  accessDenied: (req: Request, res: Response, message?: string) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "response-standardizer",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
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
@@ -95,7 +95,7 @@ const deleted = (req: Request, res: Response) => {
95
95
  const validationError = (
96
96
  req: Request,
97
97
  res: Response,
98
- errors: ErrorFields,
98
+ errors?: ErrorFields,
99
99
  message = "Validation error"
100
100
  ) => {
101
101
  res.status(400).json({ errors, message });
@@ -252,8 +252,8 @@ export const handleRestResponse = (req: Request, res: Response, response: Servic
252
252
  RestResponse.unauthorized(req, res, response?.message)
253
253
  }else if(response?.code === 403){
254
254
  RestResponse.accessDenied(req, res, response?.message)
255
- }else if(response?.code === 400 && response.errors){
256
- RestResponse.validationError(req, res, response.errors)
255
+ }else if(response?.code === 400){
256
+ RestResponse.validationError(req, res, response?.errors)
257
257
  }else if(response?.code === 500){
258
258
  RestResponse.exceptionError(req, res, response.message)
259
259
  }else if(response?.code === 404){
package/src/types.ts CHANGED
@@ -23,7 +23,7 @@ export interface Pagination<T>{
23
23
  export interface ServiceResponse {
24
24
  code: number;
25
25
  message: string;
26
- errors: Record<string, string[]> | null;
26
+ errors?: ErrorFields;
27
27
  }
28
28
 
29
29
  export type ErrorFields = Record<string, string[]>;
@@ -45,7 +45,7 @@ export interface RestResponseFunctions {
45
45
  validationError: (
46
46
  req: Request,
47
47
  res: Response,
48
- errors: ErrorFields,
48
+ errors?: ErrorFields,
49
49
  message?: string
50
50
  ) => void;
51
51
  exceptionError: (