Refactor error handling in LeaveController to return appropriate error responses instead of throwing exceptions
All checks were successful
Build & Deploy Leave Service / build (push) Successful in 1m18s

This commit is contained in:
Suphonchai Phoonsawat 2026-02-04 10:32:44 +07:00
parent 19000b2e42
commit 7775ea85c3

View file

@ -527,12 +527,13 @@ namespace BMA.EHR.Leave.Service.Controllers
if (sameTypeJob != null)
{
// ตรวจสอบว่างานที่มีอยู่ถูกสร้างเมื่อไหร่ ถ้าเกิน 2 นาทีให้สร้างใหม่ได้
var timeDiff = (currentDate - sameTypeJob.CreatedDate).TotalMinutes;
if (timeDiff < 2)
{
return Error($"มีงาน {checkType} กำลังดำเนินการอยู่ กรุณารอสักครู่", StatusCodes.Status409Conflict);
}
return Error($"มีงาน {checkType} กำลังดำเนินการอยู่", StatusCodes.Status500InternalServerError);
// var timeDiff = (currentDate - sameTypeJob.CreatedDate).TotalMinutes;
// if (timeDiff < 2)
// {
// return Error($"มีงาน {checkType} กำลังดำเนินการอยู่ กรุณารอสักครู่", StatusCodes.Status409Conflict);
// }
}
}
@ -623,7 +624,8 @@ namespace BMA.EHR.Leave.Service.Controllers
// Ignore delete error
}
}
throw new Exception($"ไม่สามารถส่งงานไปยัง Queue ได้: {ex.Message}");
return Error($"ไม่สามารถส่งงานไปยัง Queue ได้: {ex.Message}");
//throw new Exception($"ไม่สามารถส่งงานไปยัง Queue ได้: {ex.Message}");
}
finally
{