fix WebRequest#getAsEntity
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 51s
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 51s
This commit is contained in:
parent
6202aa6691
commit
da06a01097
@ -31,20 +31,26 @@ public class WebRequest {
|
|||||||
* @return the response
|
* @return the response
|
||||||
*/
|
*/
|
||||||
public static <T> T getAsEntity(String url, Class<T> clazz) throws RateLimitException {
|
public static <T> T getAsEntity(String url, Class<T> clazz) throws RateLimitException {
|
||||||
ResponseEntity<T> responseEntity = CLIENT.get()
|
try {
|
||||||
.uri(url)
|
ResponseEntity<T> responseEntity = CLIENT.get()
|
||||||
.retrieve()
|
.uri(url)
|
||||||
.onStatus(HttpStatusCode::isError, (request, response) -> {
|
.retrieve()
|
||||||
}) // Don't throw exceptions on error
|
.onStatus(HttpStatusCode::isError, (request, response) -> {
|
||||||
.toEntity(clazz);
|
}) // Don't throw exceptions on error
|
||||||
|
.toEntity(clazz);
|
||||||
|
|
||||||
if (responseEntity.getStatusCode().isError()) {
|
if (responseEntity.getStatusCode().isError()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (responseEntity.getStatusCode().isSameCodeAs(HttpStatus.TOO_MANY_REQUESTS)) {
|
||||||
|
throw new RateLimitException("Rate limit reached");
|
||||||
|
}
|
||||||
|
return responseEntity.getBody();
|
||||||
|
} catch (RateLimitException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (responseEntity.getStatusCode().isSameCodeAs(HttpStatus.TOO_MANY_REQUESTS)) {
|
|
||||||
throw new RateLimitException("Rate limit reached");
|
|
||||||
}
|
|
||||||
return responseEntity.getBody();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user