Reputation: 5871
I have the following block of code. I am getting org.springframework.web.context.request.async.AsyncRequestTimeoutException
the catch block is not handling that. Can anyone tell me how to handle the exception thrown by the below supplyAsync
block?
@org.springframework.scheduling.annotation.Async
public CompletableFuture<ResponseEntity<?>> getTeam(String teamCode) {
CompletableFuture.supplyAsync(() -> {
CricketTeam team;
try {
team = service.getTeamInfo(teamCode);
} catch (Exception ex) {
Error error = new Error(500, ex.getMessage());
return new ResponseEntity<>(error, HttpStatus.OK);
}
return new ResponseEntity<>(team, HttpStatus.OK);
});
}
Upvotes: 1
Views: 2847
Reputation: 3242
Maybe something like this (you'll have to adjust the types):
CompletableFuture.supplyAsync(() -> possiblyFailingMethod())
.exceptionally((e) ->
{
log.error("Something went wrong", e);
return "KO";
});
Upvotes: 5