Closed knuclechan closed 2 years ago
Have you try to catch the exception in the getEmployeeSalaryByDepartment
method?
@GetMapping("/{department}/salary")
public Mono<Double> getEmployeeSalaryByDepartment(@PathVariable String department) {
// Use unwrap method to transform the JPromise object back to the Mono object.
return _getEmployeeTotalSalaryByDepartment(department).unwrap(Mono.class).onErrorResume(Throwable.class, e -> {
System.out.println("I found an error: " + e.getMessage());
return Mono.empty();
});
}
If the console print I found an error: XXX
, even getEmployeeSalaryByDepartment
does not return an error mono, the error is not swallowed. Otherwise, it is really a bug, I will try to fix it.
Any news? I will close the issue if no response in a few days
close because of no response.
If an exception is not caught and re-throw in the
@Async
method, the exception is gone.Let me use your example (simplified) to explain. I assume
salaryRepository.findSalaryByDeparmentEmployee
returns a mono. If the repository throws an exception (returned error mono) , I would expect the mono unwrapped atgetEmployeeSalaryByDepartment
is an error mono too, but it is a null value mono instead. The exception is gone.But if I catch and re-throw the error in the
@Async
method, then the unwrapped mono is an error mono.I think it is reasonable to assume that uncaught exception should be passed alone instead of swallowed. If there is implementation difficulty, I think it would be better to reminder others to catch exceptions in the
@Async
method.