我有以下代码块。我发现org.springframework.web.context.request.async.AsyncRequestTimeoutExceptioncatch 块没有处理这个问题。谁能告诉我如何处理下面的块抛出的异常supplyAsync?
@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);
});
}
Run Code Online (Sandbox Code Playgroud)
也许是这样的(你必须调整类型):
CompletableFuture.supplyAsync(() -> possiblyFailingMethod())
.exceptionally((e) ->
{
log.error("Something went wrong", e);
return "KO";
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2720 次 |
| 最近记录: |