Task 1-2: Narrow Exception Handling trong Error-81 Path
Phase: 1 - Bug fixes Priority: Medium Module:
receiver-serviceDepends on: Không có Reference: docs/BountyHunter-Backend/details/feature-receiver-service/SPEC.md
Background
JMSReceiverHealthCheckMachineListener.machineErrorReport() có broad catch Exception cho error code 81 path:
try {
if (Objects.nonNull(reportData) && reportData.errorCode() == 81) {
iGameService.endGameSuccess(macIp, 1, true);
}
} catch (Exception e) {
LOGGER.error("Error ending game for machine {}: {}", macIp, e.getMessage());
}
catch Exception có thể nuốt các lỗi quan trọng như NullPointerException, database errors, etc.
Tasks
DI Note:
JMSReceiverHealthCheckMachineListenerinjectIGameServicequa constructor (hoặc@Autowired). Trước khi viết narrow catch, xác nhận exception types màIGameService.endGameSuccess()có thể throw bằng cách xem method signature và javadoc (hoặc grepthrowstrongIGameServiceimplementations).ControlServerMessageFail— xác nhận package chính xác bằng:grep -rn "class ControlServerMessageFail".
File: receiver-service/jms/JMSReceiverHealthCheckMachineListener.java
-
[ ] Xác nhận exception types của
IGameService.endGameSuccess():grep -rn "endGameSuccess\|ControlServerMessageFail" receiver-service/ application-core/ -
[ ] Replace broad
catch (Exception e)với specific exceptions:try { if (Objects.nonNull(reportData) && reportData.errorCode() == 81) { iGameService.endGameSuccess(macIp, 1, true); } } catch (ControlServerMessageFail e) { // Expected failure: control server communication issue LOGGER.error("[RECEIVER] Error ending game (ControlServerMessageFail) for machine {}: {}", macIp, e.getMessage()); } catch (RuntimeException e) { // Unexpected failure: re-throw or alert for investigation LOGGER.error("[RECEIVER] Unexpected error ending game for machine {}. ErrorCode=81", macIp, e); // Consider: alertingService.sendAlert(...) cho unexpected runtime errors throw e; // hoặc handle tùy policy: re-throw để trigger JMS redelivery } -
[ ] Xác định policy: unexpected
RuntimeExceptiontrong error-81 path nên re-throw (trigger retry) hay swallow (avoid requeue loop)?
Verification / Acceptance Criteria
- [ ] Không còn bare
catch (Exception e)trong error-81 path - [ ]
ControlServerMessageFailđược catch riêng với log ERROR - [ ] Unexpected
RuntimeException(ví dụ:NullPointerExceptiondo data issue) → không bị nuốt thầm lặng - [ ] Unit test: mock
IGameService.endGameSuccess()throwControlServerMessageFail→ log error, không re-throw - [ ] Unit test: mock throw
RuntimeException→ behavior theo policy đã chọn
Files to Modify
receiver-service/src/main/java/com/figpop/jms/JMSReceiverHealthCheckMachineListener.java