|
@@ -50,6 +50,24 @@ class PRAS {
|
|
|
res.json(this.getPRASResultObject(statusCode, status, message, data, code, extra));
|
|
|
},
|
|
|
};
|
|
|
+ if (/application\/json/.test(res.get("Content-Type"))) {
|
|
|
+ const originalSend = res.send;
|
|
|
+ res.send = (body) => {
|
|
|
+ if (typeof body === "string") {
|
|
|
+ body = JSON.parse(body);
|
|
|
+ }
|
|
|
+ if (typeof body === "string") {
|
|
|
+ body = { data: body };
|
|
|
+ }
|
|
|
+ else if (!body.hasOwnProperty("data")) {
|
|
|
+ body = { data: body };
|
|
|
+ }
|
|
|
+ const prasBody = this.getPRASResultObject(body.statusCode, body.status, body.message, body.data, body.code, body.extra);
|
|
|
+ res.status(Number(prasBody) || null);
|
|
|
+ delete prasBody.statusCode;
|
|
|
+ return originalSend(JSON.stringify(prasBody));
|
|
|
+ };
|
|
|
+ }
|
|
|
next();
|
|
|
};
|
|
|
}
|