don't return maxmind data if it failed to load

This commit is contained in:
Lee 2024-04-21 23:33:40 +01:00
parent 2ad5556041
commit 67efda71d2
2 changed files with 8 additions and 2 deletions

@ -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(),

@ -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) {