From 546a187f521c6159ee3c90f81a330a67a02d76d3 Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Wed, 10 Apr 2024 02:25:54 -0400 Subject: [PATCH] Remove InvalidMinecraftServerPlatformException --- .../mc/controller/ServerController.java | 6 +-- .../impl/InvalidMinecraftServerPlatform.java | 41 ------------------- .../me/braydon/mc/service/MojangService.java | 10 ++--- 3 files changed, 6 insertions(+), 51 deletions(-) delete mode 100644 src/main/java/me/braydon/mc/exception/impl/InvalidMinecraftServerPlatform.java diff --git a/src/main/java/me/braydon/mc/controller/ServerController.java b/src/main/java/me/braydon/mc/controller/ServerController.java index 7fd47bf..eb55fd9 100644 --- a/src/main/java/me/braydon/mc/controller/ServerController.java +++ b/src/main/java/me/braydon/mc/controller/ServerController.java @@ -26,7 +26,6 @@ package me.braydon.mc.controller; import lombok.NonNull; import lombok.extern.log4j.Log4j2; import me.braydon.mc.exception.impl.BadRequestException; -import me.braydon.mc.exception.impl.InvalidMinecraftServerPlatform; import me.braydon.mc.exception.impl.ResourceNotFoundException; import me.braydon.mc.model.MinecraftServer; import me.braydon.mc.model.cache.CachedMinecraftServer; @@ -65,14 +64,13 @@ public final class ServerController { * @param platform the platform of the server * @param hostname the hostname of the server * @return the server - * @throws BadRequestException if the hostname is unknown - * @throws InvalidMinecraftServerPlatform if the platform is invalid + * @throws BadRequestException if the hostname or platform is invalid * @throws ResourceNotFoundException if the server isn't found */ @GetMapping("/{platform}/{hostname}") @ResponseBody public ResponseEntity getServer(@PathVariable @NonNull String platform, @PathVariable @NonNull String hostname) - throws BadRequestException, InvalidMinecraftServerPlatform, ResourceNotFoundException + throws BadRequestException, ResourceNotFoundException { return ResponseEntity.ofNullable(mojangService.getMinecraftServer(platform, hostname)); } diff --git a/src/main/java/me/braydon/mc/exception/impl/InvalidMinecraftServerPlatform.java b/src/main/java/me/braydon/mc/exception/impl/InvalidMinecraftServerPlatform.java deleted file mode 100644 index f58ded1..0000000 --- a/src/main/java/me/braydon/mc/exception/impl/InvalidMinecraftServerPlatform.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2024 Braydon (Rainnny). - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package me.braydon.mc.exception.impl; - -import me.braydon.mc.model.MinecraftServer; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -/** - * This exception is raised when a {@link MinecraftServer} - * lookup is made for an invalid {@link MinecraftServer.Platform}. - * - * @author Braydon - */ -@ResponseStatus(HttpStatus.BAD_REQUEST) -public final class InvalidMinecraftServerPlatform extends RuntimeException { - public InvalidMinecraftServerPlatform() { - super("Invalid Minecraft server platform"); - } -} \ No newline at end of file diff --git a/src/main/java/me/braydon/mc/service/MojangService.java b/src/main/java/me/braydon/mc/service/MojangService.java index 7fa88b7..08c8739 100644 --- a/src/main/java/me/braydon/mc/service/MojangService.java +++ b/src/main/java/me/braydon/mc/service/MojangService.java @@ -35,7 +35,6 @@ import me.braydon.mc.common.*; import me.braydon.mc.common.web.JsonWebException; import me.braydon.mc.common.web.JsonWebRequest; import me.braydon.mc.exception.impl.BadRequestException; -import me.braydon.mc.exception.impl.InvalidMinecraftServerPlatform; import me.braydon.mc.exception.impl.MojangRateLimitException; import me.braydon.mc.exception.impl.ResourceNotFoundException; import me.braydon.mc.model.*; @@ -283,7 +282,7 @@ public final class MojangService { icon = favicon.getBase64(); icon = icon.substring(icon.indexOf(",") + 1); // Remove the data type from the server icon } - } catch (BadRequestException | InvalidMinecraftServerPlatform | ResourceNotFoundException ignored) { + } catch (BadRequestException | ResourceNotFoundException ignored) { // Safely ignore these, we will use the default server icon } if (icon == null) { // Use the default server icon @@ -346,16 +345,15 @@ public final class MojangService { * @param platformName the name of the platform * @param hostname the hostname of the server * @return the resolved Minecraft server - * @throws BadRequestException if the hostname is unknown - * @throws InvalidMinecraftServerPlatform if the platform is invalid + * @throws BadRequestException if the hostname or platform is invalid * @throws ResourceNotFoundException if the server isn't found */ @NonNull public CachedMinecraftServer getMinecraftServer(@NonNull String platformName, @NonNull String hostname) - throws BadRequestException, InvalidMinecraftServerPlatform, ResourceNotFoundException { + throws BadRequestException, ResourceNotFoundException { MinecraftServer.Platform platform = EnumUtils.getEnumConstant(MinecraftServer.Platform.class, platformName.toUpperCase()); if (platform == null) { // Invalid platform - throw new InvalidMinecraftServerPlatform(); + throw new BadRequestException("Invalid platform: %s".formatted(platformName)); } String lookupHostname = hostname; // The hostname used to lookup the server