fixed service stop working
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m6s

This commit is contained in:
Warunee Tamkoo 2026-07-09 21:45:30 +07:00
parent 759e69d44d
commit e69320005c
2 changed files with 19 additions and 1 deletions

View file

@ -21,6 +21,24 @@ import { DateSerializer } from "./interfaces/date-serializer";
import { initWebSocket } from "./services/webSocket";
import { RetirementService } from "./services/RetirementService";
// ── Process-level safety nets ──────────────────────────────────────────────
// ตาข่ายกัน service ตายจาก promise ที่ reject แล้วไม่ถูกจับ / exception ที่หลุด
// ออกมา (เช่น bug เรียก async โดยไม่ await ใน PermissionController).
// ลงทะเบียนไว้ให้เร็วที่สุด ก่อนที่ main() จะเริ่มทำงาน
process.on("unhandledRejection", (reason) => {
console.error(
"[APP][unhandledRejection] A promise was rejected but never caught:",
reason,
);
});
process.on("uncaughtException", (err) => {
// คง service ไว้เพื่อ availability สูงสุด
// หมายเหตุ: process อาจอยู่ในสถานะไม่สม่ำเสมอ ควร monitor log นี้และ restart
// ในช่วงเวลาที่เหมาะสม ถ้าต้องการ crash-on-error ให้เปลี่ยนเป็น graceful
// shutdown + process.exit(1) ตรงนี้
console.error("[APP][uncaughtException] An exception escaped all handlers:", err);
});
async function main() {
await AppDataSource.initialize();

View file

@ -810,7 +810,7 @@ export class PermissionController extends Controller {
});
const getAsync = promisify(redisClient.get).bind(redisClient);
let org = this.PermissionOrg(request, system, action);
let org = await this.PermissionOrg(request, system, action);
let reply = await getAsync("user_" + id);
if (reply != null) {
reply = JSON.parse(reply);