문제

(겉으로는) 알려진 좋은 웹 서비스를 호출하는 간단한 정적 메소드.

서비스 일치하는 레코드가 없으면 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);
.

그러나 이미 시도가 아프게됩니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top