2016-11-14 1 views
1

다음 코드 블록이 있습니다. org.springframework.web.context.request.async.AsyncRequestTimeoutException catch 블록이 처리하지 않습니다. 아무도 아래 supplyAsync 블록에 의해 던져 예외를 처리하는 방법을 말해 줄래?CompletableFuture.supplyAsync에 의해 throw 된 예외를 처리하는 방법

@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); 
     }); 

} 
+0

당신이 시도/catch 문으로 모든 것을 포장 해봤를? –

+0

전체 supplyAsync 블록을 의미합니까? – Jobin

+1

'오류'란 무엇입니까? 게다가'try' 본문 내에서 던져진 예외 만 잡을 수 있습니다. 당신은'AsyncRequestTimeoutException'이 던져지는 곳을 분명히하지 않았습니다. – Holger

답변

3

어쩌면이 같은 (당신이 유형 조정해야합니다) :

CompletableFuture.supplyAsync(() -> possiblyFailingMethod()) 
      .exceptionally((e) -> 
        { 
         log.error("Something went wrong", e); 
         return "KO"; 
      }); 
관련 문제