fix ไม่บันทึก log (Endpoint ไฟล์) #223
This commit is contained in:
parent
eb2f4c8b1b
commit
8fc32940c5
1 changed files with 12 additions and 1 deletions
|
|
@ -59,6 +59,17 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) {
|
|||
// Get rootId from token
|
||||
const rootId = req.app.locals.logData?.orgRootDnaId;
|
||||
|
||||
let _msg = data?.message;
|
||||
if (!_msg) {
|
||||
if (res.statusCode >= 500) {
|
||||
_msg = "ไม่สำเร็จ";
|
||||
} else if (res.statusCode >= 400) {
|
||||
_msg = "พบข้อผิดพลาด";
|
||||
} else if (res.statusCode >= 200) {
|
||||
_msg = "สำเร็จ";
|
||||
}
|
||||
}
|
||||
|
||||
const obj = {
|
||||
logType: res.statusCode >= 500 ? "error" : res.statusCode >= 400 ? "warning" : "info",
|
||||
ip: req.ip,
|
||||
|
|
@ -71,7 +82,7 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) {
|
|||
method: req.method,
|
||||
endpoint: req.url,
|
||||
responseCode: String(res.statusCode === 304 ? 200 : res.statusCode),
|
||||
responseDescription: data?.message,
|
||||
responseDescription: _msg,
|
||||
input: level === 4 ? JSON.stringify(req.body, null, 2) : undefined,
|
||||
output: level === 4 ? JSON.stringify(data, null, 2) : undefined,
|
||||
...req.app.locals.logData,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue