質問

(一見)既知の良いWebサービスを呼び出す単純な静的メソッド。

サービス一致するレコードが見つからない場合は、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);
.

しかし、これはすでにTry Catch Blockに包まれています。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top