Open Isma399 opened 2 years ago
You can use standard lua error handling via pcall
, e.g. something like:
function geoip(ip)
local ok, res, status = pcall(db.lookup, db, ip)
if not ok then return nil end
local ok, val = pcall(res.get, res, "country", "iso_code")
if not ok then return nil end
return val
end
Though it might make sense to add or modify the methods to not generate hard error on "not found" error, but instead return nil
.
Thank you, that works very well! I don't event expect that you answer me so thanks again. I've also thought to modify line82 of maxminddb.c to return nil. But I don't know of to write that in C.
Hello, thanks for this lib. We try to use it to localize mail sender, testing step was ok with some ips. But passing it in prod breaks. Is there a way to handle error when IP is in mmdb but not data :
Script breaks on 165.72.200.98 :