Fail properly if MaxMind fails to respond / returns invalid data
This commit is contained in:
parent
77c3e49048
commit
527f465c12
@ -45,7 +45,7 @@ public final class IpIntel {
|
||||
MaxMindUtils.getInsights(id, (maxMindResult, error2) -> {
|
||||
if (error2 != null) {
|
||||
callback.onResult(null, error2);
|
||||
} else {
|
||||
} else if (maxMindResult != null) {
|
||||
IpIntel newIpIntel = new IpIntel(id, maxMindResult);
|
||||
|
||||
ipIntelCollection.insertOne(newIpIntel, (ignored, error3) -> {
|
||||
@ -55,6 +55,9 @@ public final class IpIntel {
|
||||
callback.onResult(newIpIntel, null);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// MaxMind failed to return result
|
||||
callback.onResult(null, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -90,6 +93,12 @@ public final class IpIntel {
|
||||
return;
|
||||
}
|
||||
|
||||
// MaxMind failed to return result
|
||||
if (maxMindResult == null) {
|
||||
createNewIntelFuture.complete();
|
||||
return;
|
||||
}
|
||||
|
||||
IpIntel newIpIntel = new IpIntel(ip, maxMindResult);
|
||||
|
||||
ipIntelCollection.insertOne(newIpIntel, (ignored, error3) -> {
|
||||
|
@ -26,7 +26,13 @@ public class MaxMindUtils {
|
||||
httpsClient.get(443, "geoip.maxmind.com", "/geoip/v2.1/insights/" + ip, (response) -> {
|
||||
response.bodyHandler((body) -> {
|
||||
JsonObject bodyJson = new JsonObject(body.toString());
|
||||
callback.onResult(new MaxMindResult(bodyJson), null);
|
||||
|
||||
try {
|
||||
MaxMindResult maxMindResult = new MaxMindResult(bodyJson);
|
||||
callback.onResult(maxMindResult, null);
|
||||
} catch (Exception ignored) {
|
||||
callback.onResult(null, null);
|
||||
}
|
||||
});
|
||||
|
||||
response.exceptionHandler((error) -> callback.onResult(null, error));
|
||||
|
Loading…
Reference in New Issue
Block a user