From 67efda71d233a947c720c2b81d6996cd399b19ab Mon Sep 17 00:00:00 2001 From: Liam Date: Sun, 21 Apr 2024 23:33:40 +0100 Subject: [PATCH] don't return maxmind data if it failed to load --- .../xyz/mcutils/backend/model/server/MinecraftServer.java | 3 +++ .../java/xyz/mcutils/backend/service/MaxMindService.java | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/xyz/mcutils/backend/model/server/MinecraftServer.java b/src/main/java/xyz/mcutils/backend/model/server/MinecraftServer.java index fd23887..763d5ad 100644 --- a/src/main/java/xyz/mcutils/backend/model/server/MinecraftServer.java +++ b/src/main/java/xyz/mcutils/backend/model/server/MinecraftServer.java @@ -191,6 +191,9 @@ public class MinecraftServer { * @return the location of the server */ public static GeoLocation fromMaxMind(CityResponse response) { + if (response == null) { + return null; + } return new GeoLocation( response.getCountry().getName(), response.getMostSpecificSubdivision().getName(), diff --git a/src/main/java/xyz/mcutils/backend/service/MaxMindService.java b/src/main/java/xyz/mcutils/backend/service/MaxMindService.java index 3f2392a..da06cee 100644 --- a/src/main/java/xyz/mcutils/backend/service/MaxMindService.java +++ b/src/main/java/xyz/mcutils/backend/service/MaxMindService.java @@ -40,8 +40,8 @@ public class MaxMindService { public MaxMindService(@Value("${maxmind.license}") String maxMindLicense) { this.maxMindLicense = maxMindLicense; if (maxMindLicense.isBlank()) { - log.error("The MaxMind license key is not set, please set it in the configuration and try again"); - System.exit(1); + log.error("The MaxMind license key is not set, please set it in the configuration and try again, disabling the MaxMind service..."); + return; } File databaseFile = loadDatabase(); @@ -61,6 +61,9 @@ public class MaxMindService { * @return The GeoIP information */ public static CityResponse lookup(String query) { + if (database == null) { // The database isn't loaded, return null + return null; + } try { return database.city(InetAddress.getByName(query)); } catch (IOException | GeoIp2Exception e) {