diff --git a/src/middlewares/logs.ts b/src/middlewares/logs.ts index 4bcf111..2ae251c 100644 --- a/src/middlewares/logs.ts +++ b/src/middlewares/logs.ts @@ -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,