catch query errors

This commit is contained in:
keyan 2023-12-20 20:05:09 -06:00
parent 0be553296d
commit 01bc3dd752
1 changed files with 9 additions and 4 deletions

View File

@ -15,10 +15,15 @@ export async function gOFACYourself ({ models, headers = {}, ip }) {
ip ||= xRealIp || xForwardedFor?.split(',')?.[0]
if (!ip) return false
const countries = await models.$queryRaw`
SELECT * FROM "OFAC" WHERE iprange("startIP","endIP") >>= ${ip}::ipaddress`
try {
const countries = await models.$queryRaw`
SELECT * FROM "OFAC" WHERE iprange("startIP","endIP") >>= ${ip}::ipaddress`
if (countries.length === 0) return false
if (countries.length === 0) return false
return countries[0].country
return countries[0].country
} catch (e) {
console.error('gOFACYourself', e)
return false
}
}