From f9bd49c4bb93879f82b8242c7eb12a6ad09645cb Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Wed, 24 Apr 2024 15:42:44 -0400 Subject: [PATCH] Fallback to null for addr not found in MaxMind --- .../java/cc/restfulmc/api/service/MaxMindService.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/API/src/main/java/cc/restfulmc/api/service/MaxMindService.java b/API/src/main/java/cc/restfulmc/api/service/MaxMindService.java index 98a0aea..f7f66d6 100644 --- a/API/src/main/java/cc/restfulmc/api/service/MaxMindService.java +++ b/API/src/main/java/cc/restfulmc/api/service/MaxMindService.java @@ -25,6 +25,7 @@ package cc.restfulmc.api.service; import com.maxmind.db.CHMCache; import com.maxmind.geoip2.DatabaseReader; +import com.maxmind.geoip2.exception.AddressNotFoundException; import com.maxmind.geoip2.model.CityResponse; import jakarta.annotation.PostConstruct; import jakarta.annotation.PreDestroy; @@ -113,7 +114,12 @@ public final class MaxMindService { @SneakyThrows public CityResponse lookupCity(@NonNull InetAddress address) { DatabaseReader database = getDatabase(Database.CITY); - return database == null ? null : database.city(address); + try { + return database == null ? null : database.city(address); + } catch (AddressNotFoundException ignored) { + // Safely ignore this and return null instead + return null; + } } /**