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) -> {
|
MaxMindUtils.getInsights(id, (maxMindResult, error2) -> {
|
||||||
if (error2 != null) {
|
if (error2 != null) {
|
||||||
callback.onResult(null, error2);
|
callback.onResult(null, error2);
|
||||||
} else {
|
} else if (maxMindResult != null) {
|
||||||
IpIntel newIpIntel = new IpIntel(id, maxMindResult);
|
IpIntel newIpIntel = new IpIntel(id, maxMindResult);
|
||||||
|
|
||||||
ipIntelCollection.insertOne(newIpIntel, (ignored, error3) -> {
|
ipIntelCollection.insertOne(newIpIntel, (ignored, error3) -> {
|
||||||
@ -55,6 +55,9 @@ public final class IpIntel {
|
|||||||
callback.onResult(newIpIntel, null);
|
callback.onResult(newIpIntel, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
// MaxMind failed to return result
|
||||||
|
callback.onResult(null, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -90,6 +93,12 @@ public final class IpIntel {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MaxMind failed to return result
|
||||||
|
if (maxMindResult == null) {
|
||||||
|
createNewIntelFuture.complete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
IpIntel newIpIntel = new IpIntel(ip, maxMindResult);
|
IpIntel newIpIntel = new IpIntel(ip, maxMindResult);
|
||||||
|
|
||||||
ipIntelCollection.insertOne(newIpIntel, (ignored, error3) -> {
|
ipIntelCollection.insertOne(newIpIntel, (ignored, error3) -> {
|
||||||
|
@ -26,7 +26,13 @@ public class MaxMindUtils {
|
|||||||
httpsClient.get(443, "geoip.maxmind.com", "/geoip/v2.1/insights/" + ip, (response) -> {
|
httpsClient.get(443, "geoip.maxmind.com", "/geoip/v2.1/insights/" + ip, (response) -> {
|
||||||
response.bodyHandler((body) -> {
|
response.bodyHandler((body) -> {
|
||||||
JsonObject bodyJson = new JsonObject(body.toString());
|
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));
|
response.exceptionHandler((error) -> callback.onResult(null, error));
|
||||||
|
Loading…
Reference in New Issue
Block a user