cleanup WebRequest

This commit is contained in:
Lee 2024-04-13 15:41:08 +01:00
parent 471c3e6e80
commit 57601acbb1
3 changed files with 3 additions and 5 deletions

@ -2,7 +2,6 @@ package cc.fascinated.common;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode; import org.springframework.http.HttpStatusCode;
import java.util.List; import java.util.List;

@ -35,7 +35,6 @@ public class WebRequest {
ResponseEntity<T> profile = CLIENT.get() ResponseEntity<T> profile = CLIENT.get()
.uri(url) .uri(url)
.retrieve() .retrieve()
.onStatus(HttpStatusCode::isError, (request, response) -> {}) // Don't throw exceptions on error
.toEntity(clazz); .toEntity(clazz);
if (profile.getStatusCode().isError()) { if (profile.getStatusCode().isError()) {
@ -53,11 +52,11 @@ public class WebRequest {
* @param url the url * @param url the url
* @return the response * @return the response
*/ */
public static ResponseEntity<?> getAndIgnoreErrors(String url) { public static ResponseEntity<?> get(String url, Class<?> clazz) {
return CLIENT.get() return CLIENT.get()
.uri(url) .uri(url)
.retrieve() .retrieve()
.onStatus(HttpStatusCode::isError, (request, response) -> {}) // Don't throw exceptions on error .onStatus(HttpStatusCode::isError, (request, response) -> {}) // Don't throw exceptions on error
.toEntity(String.class); .toEntity(clazz);
} }
} }

@ -192,7 +192,7 @@ public class MojangService {
Map<String, Boolean> endpoints = new HashMap<>(); Map<String, Boolean> endpoints = new HashMap<>();
for (EndpointStatus endpoint : MOJANG_ENDPOINTS) { for (EndpointStatus endpoint : MOJANG_ENDPOINTS) {
boolean online = false; boolean online = false;
ResponseEntity<?> response = WebRequest.getAndIgnoreErrors(endpoint.getEndpoint()); ResponseEntity<?> response = WebRequest.get(endpoint.getEndpoint(), String.class);
if (endpoint.getAllowedStatuses().contains(response.getStatusCode())) { if (endpoint.getAllowedStatuses().contains(response.getStatusCode())) {
online = true; online = true;
} }