add mojang api rate limit error
All checks were successful
ci / deploy (push) Successful in 1m14s

This commit is contained in:
Lee
2024-04-10 09:30:35 +01:00
parent 330c3efc78
commit 2e58d9c925
7 changed files with 58 additions and 27 deletions

View File

@ -1,6 +1,8 @@
package cc.fascinated.common;
import cc.fascinated.exception.impl.RateLimitException;
import lombok.experimental.UtilityClass;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.HttpClientErrorException;
@ -33,6 +35,9 @@ public class WebRequest {
if (profile.getStatusCode().isError()) {
return null;
}
if (profile.getStatusCode().isSameCodeAs(HttpStatus.TOO_MANY_REQUESTS)) {
throw new RateLimitException("Rate limit reached");
}
return profile.getBody();
} catch (HttpClientErrorException ex) {
return null;