Last active
January 2, 2016 19:19
-
-
Save flavienlaurent/8350081 to your computer and use it in GitHub Desktop.
How to retry request with http-request lib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface HttpRequestBuilder { | |
public HttpRequest build(); | |
} | |
HttpRequestBuilder builder = new HttpRequestBuilder { | |
@Override | |
public HttpRequest build() { | |
return HttpRequest.get("uri").acceptJson().userAgent("useragent"); | |
} | |
} | |
//to retry on SocketTimeoutException for example | |
HttpRequest httpRequest = builder.build(); | |
try { | |
boolean ok = httpRequest.ok(); | |
//... | |
} catch(HttpRequest.HttpRequestException e) { | |
if(e.getCause() instanceof SocketTimeoutException) { | |
//repeat it | |
httpRequest = builder.build(); | |
httpRequest.code(); | |
//... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment