diff --git a/lib/detect.ts b/lib/detect.ts index f431f02e..8b11cd79 100644 --- a/lib/detect.ts +++ b/lib/detect.ts @@ -71,8 +71,8 @@ export async function getLocation(ip) { const result = lookup.get(ip); const country = result?.country?.iso_code ?? result?.registered_country?.iso_code; - const subdivision1 = result?.subdivisions[0]?.iso_code; - const subdivision2 = result?.subdivisions[1]?.names?.en; + const subdivision1 = result?.subdivisions?.[0]?.iso_code; + const subdivision2 = result?.subdivisions?.[1]?.names?.en; const city = result?.city?.names?.en; return { country, subdivision1, subdivision2, city };