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
All checks were successful
Build & Deploy Leave Service / build (push) Successful in 1m18s
This commit is contained in:
parent
19000b2e42
commit
7775ea85c3
1 changed files with 9 additions and 7 deletions
|
|
@ -527,12 +527,13 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
|
|
||||||
if (sameTypeJob != null)
|
if (sameTypeJob != null)
|
||||||
{
|
{
|
||||||
// ตรวจสอบว่างานที่มีอยู่ถูกสร้างเมื่อไหร่ ถ้าเกิน 2 นาทีให้สร้างใหม่ได้
|
|
||||||
var timeDiff = (currentDate - sameTypeJob.CreatedDate).TotalMinutes;
|
return Error($"มีงาน {checkType} กำลังดำเนินการอยู่", StatusCodes.Status500InternalServerError);
|
||||||
if (timeDiff < 2)
|
// var timeDiff = (currentDate - sameTypeJob.CreatedDate).TotalMinutes;
|
||||||
{
|
// if (timeDiff < 2)
|
||||||
return Error($"มีงาน {checkType} กำลังดำเนินการอยู่ กรุณารอสักครู่", StatusCodes.Status409Conflict);
|
// {
|
||||||
}
|
// return Error($"มีงาน {checkType} กำลังดำเนินการอยู่ กรุณารอสักครู่", StatusCodes.Status409Conflict);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -623,7 +624,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
// Ignore delete error
|
// Ignore delete error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new Exception($"ไม่สามารถส่งงานไปยัง Queue ได้: {ex.Message}");
|
return Error($"ไม่สามารถส่งงานไปยัง Queue ได้: {ex.Message}");
|
||||||
|
//throw new Exception($"ไม่สามารถส่งงานไปยัง Queue ได้: {ex.Message}");
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue