Play Framework 2.2 (Java) WS 복구 블록은 HTTP 예외를 catch하지 않습니다.
-
21-12-2019 - |
문제
(겉으로는) 알려진 좋은 웹 서비스를 호출하는 간단한 정적 메소드.
서비스 일치하는 레코드가 없으면 HTTP 500 / 내부 서버 오류를 반환하지만 호출 복구 블록은 실행되지 않습니다.
나는 분명히 누락되었거나 뭔가를 뻔뻔스럽게 멍청하고
public static Promise<Property> ByPhone(String phone) {
return WS.url("http://localhost:9000/data/property/" + phone)
.get ()
.map (
new Function<WS.Response, Property>() {
public Property apply (WS.Response response) {
System.out.println("got here: " + response.getStatusText());
Property property = null;
try {
property = _mapper.readValue(response.getBody(), Property.class);
} catch (Throwable t) {
t.printStackTrace();
}
return property;
}
}
).recover (
new Function<Throwable, Property>() {
public Property apply (Throwable t) {
System.out.println("never get here");
t.printStackTrace();
return null;
}
}
);
}
. 해결책
recover
는 잡히지 않는 예외로부터 복구를 돕습니다.이 경우 HTTP 500 응답이 지정되지 않은 Throwable
아마도 500은 다음 블록이 오류를 던지게 할 것이라는 것을 의미합니다.
property = _mapper.readValue(response.getBody(), Property.class);
.
그러나 이미 시도가 아프게됩니다.
제휴하지 않습니다 StackOverflow