response-standardizer 1.3.0 → 1.3.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/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/package.json +1 -1
- package/src/index.ts +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export declare const error: (message: string, meta?: any) => void;
|
|
|
23
23
|
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
|
-
export declare const response: (req: Request, res: Response, response: ServiceResponse, handler?:
|
|
26
|
+
export declare const response: (req: Request, res: Response, response: ServiceResponse, handler?: (eq: Request, res: Response, data?: any) => void) => void;
|
|
27
27
|
export declare const handleServiceException: (message: string, err: any) => ServiceResponse;
|
|
28
28
|
export interface ServiceResponse {
|
|
29
29
|
}
|
|
@@ -35,5 +35,5 @@ export declare class ServiceException implements ServiceResponse {
|
|
|
35
35
|
}
|
|
36
36
|
export declare class ServiceResponseSuccess implements ServiceResponse {
|
|
37
37
|
entity: any;
|
|
38
|
-
constructor(entity
|
|
38
|
+
constructor(entity?: any);
|
|
39
39
|
}
|
package/dist/index.js
CHANGED
|
@@ -179,7 +179,7 @@ const log = (level, message, meta) => {
|
|
|
179
179
|
console.log(`${color}[${timestamp}][${location}][${level}] ${message}${metaStr}${colors.RESET}`);
|
|
180
180
|
};
|
|
181
181
|
exports.log = log;
|
|
182
|
-
const response = (req, res, response, handler = (eq, res, data) => { }) => {
|
|
182
|
+
const response = (req, res, response, handler = (eq, res, data = null) => { }) => {
|
|
183
183
|
if (response instanceof ServiceException) {
|
|
184
184
|
if (response?.code === 401) {
|
|
185
185
|
return exports.RestResponse.unauthorized(req, res, response?.message);
|
|
@@ -198,7 +198,7 @@ const response = (req, res, response, handler = (eq, res, data) => { }) => {
|
|
|
198
198
|
}
|
|
199
199
|
return exports.RestResponse.exceptionError(req, res, response.message);
|
|
200
200
|
}
|
|
201
|
-
return handler(req, res, response);
|
|
201
|
+
return handler(req, res, response.entity);
|
|
202
202
|
};
|
|
203
203
|
exports.response = response;
|
|
204
204
|
const handleServiceException = (message, err) => {
|
|
@@ -239,7 +239,7 @@ class ServiceException {
|
|
|
239
239
|
}
|
|
240
240
|
exports.ServiceException = ServiceException;
|
|
241
241
|
class ServiceResponseSuccess {
|
|
242
|
-
constructor(entity) {
|
|
242
|
+
constructor(entity = null) {
|
|
243
243
|
this.entity = entity;
|
|
244
244
|
}
|
|
245
245
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -231,7 +231,7 @@ export const response = (
|
|
|
231
231
|
req: Request,
|
|
232
232
|
res: Response,
|
|
233
233
|
response: ServiceResponse,
|
|
234
|
-
handler =
|
|
234
|
+
handler = (eq: Request, res: Response, data: any = null) => {}
|
|
235
235
|
) => {
|
|
236
236
|
if(response instanceof ServiceException){
|
|
237
237
|
if(response?.code === 401){
|
|
@@ -247,7 +247,7 @@ export const response = (
|
|
|
247
247
|
}
|
|
248
248
|
return RestResponse.exceptionError(req, res, response.message)
|
|
249
249
|
}
|
|
250
|
-
return handler(req, res, response)
|
|
250
|
+
return handler(req, res, (response as ServiceResponseSuccess).entity)
|
|
251
251
|
}
|
|
252
252
|
export const handleServiceException = (message: string, err: any) : ServiceResponse => {
|
|
253
253
|
if(err instanceof ZodError){
|
|
@@ -282,5 +282,5 @@ export class ServiceException implements ServiceResponse {
|
|
|
282
282
|
constructor(public code: number, public message: string, public errors?: ErrorFields) {}
|
|
283
283
|
}
|
|
284
284
|
export class ServiceResponseSuccess implements ServiceResponse {
|
|
285
|
-
constructor(public entity: any) {}
|
|
285
|
+
constructor(public entity: any = null) {}
|
|
286
286
|
}
|