Your response.recover(...)returns Promise<Response>that you are not using. That is, you must reassign or use the promise returned from response.recover(...).
Like in this example:
Application.java
public class Application extends Controller {
public static Result timeout() throws Exception {
int timeout = 2000;
Thread.sleep(timeout);
return ok(format("Just give me %d seconds!", timeout / 1000));
}
public static Promise<Result> takeSomeTime() throws Exception {
return couldBeAWhile().map(new F.Function<String, Result>() {
@Override
public Result apply(final String body) throws Throwable {
return ok(body);
}
});
}
public static Promise<String> couldBeAWhile() {
Promise<WSResponse> response = WS.url("http://localhost:9000/timeout")
.setTimeout(1000)
.get();
Promise<String> promise = response.map(new F.Function<WSResponse, String>() {
@Override
public String apply(final WSResponse wsResponse) throws Throwable {
return wsResponse.getBody();
}
});
promise = promise.recover(new F.Function<Throwable, String>() {
public String apply(Throwable t) throws Throwable {
Logger.error("Error ->", t);
return "error";
}
});
return promise;
}
routes
GET /timeout controllers.Application.timeout()
GET /takeSomeTime controllers.Application.takeSomeTime()
, Promise Promise :
...
promise = promise.recover(new F.Function<Throwable, String>() {
public String apply(Throwable t) throws Throwable {
Logger.error("Error ->", t);
return "error";
}
});
return promise;
, http://localhost:9000/takeSomeTime, "error" .
, , , , :
public Promise<Response> getDetails(final Place place) {
Logger.debug(BASE_URL + place.getFqId() + "?client_id=" + KEY + "&client_secret=" + SECRET_KEY + "&v=20140806&m=foursquare");
Promise<Response> response =
WS.url(BASE_URL + place.getFqId())
.setQueryParameter("client_id", KEY)
.setQueryParameter("client_secret", SECRET_KEY)
.setQueryParameter("v", "20140806")
.setQueryParameter("m", "foursquare")
.setTimeout(TIMEOUT)
.get().map(
new Function<WSResponse, Response>() {
public Response apply(WSResponse response) {
JsonNode json = response.asJson();
return new FoursquareResponse(place.getFqId(), json);
}
}
).recover(new Function<Throwable, Response>() {
public Response apply(Throwable t) throws Throwable {
Logger.error("error", t);
Logger.error(place.getFqId());
return new FoursquareResponse(place.getFqId(), null);
}
});
return response;
}