forked from Fascinated/Bat
fix WebRequest#getAsEntity
This commit is contained in:
parent
6202aa6691
commit
da06a01097
@ -31,20 +31,26 @@ public class WebRequest {
|
||||
* @return the response
|
||||
*/
|
||||
public static <T> T getAsEntity(String url, Class<T> clazz) throws RateLimitException {
|
||||
ResponseEntity<T> responseEntity = CLIENT.get()
|
||||
.uri(url)
|
||||
.retrieve()
|
||||
.onStatus(HttpStatusCode::isError, (request, response) -> {
|
||||
}) // Don't throw exceptions on error
|
||||
.toEntity(clazz);
|
||||
try {
|
||||
ResponseEntity<T> responseEntity = CLIENT.get()
|
||||
.uri(url)
|
||||
.retrieve()
|
||||
.onStatus(HttpStatusCode::isError, (request, response) -> {
|
||||
}) // 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;
|
||||
}
|
||||
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