developer #4
@ -17,13 +17,18 @@ export async function fetchPrefeituraInfo(dominio: string): Promise<PrefeituraIn
|
|||||||
if (!dominio) return null
|
if (!dominio) return null
|
||||||
|
|
||||||
const cacheKey = `prefeitura:${dominio}`
|
const cacheKey = `prefeitura:${dominio}`
|
||||||
const cached = await useRedis().get(cacheKey)
|
let redisAvailable = true
|
||||||
if (cached) {
|
try {
|
||||||
try {
|
const cached = await useRedis().get(cacheKey)
|
||||||
return JSON.parse(cached) as PrefeituraInfo
|
if (cached) {
|
||||||
} catch {
|
try {
|
||||||
// cache corrompido — segue para refetch
|
return JSON.parse(cached) as PrefeituraInfo
|
||||||
|
} catch {
|
||||||
|
// cache corrompido — segue para refetch
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
redisAvailable = false
|
||||||
}
|
}
|
||||||
|
|
||||||
const cfg = useRuntimeConfig()
|
const cfg = useRuntimeConfig()
|
||||||
@ -35,7 +40,9 @@ export async function fetchPrefeituraInfo(dominio: string): Promise<PrefeituraIn
|
|||||||
const info = res?.data
|
const info = res?.data
|
||||||
if (!info?.codigoMunicipio) return null
|
if (!info?.codigoMunicipio) return null
|
||||||
|
|
||||||
await useRedis().set(cacheKey, JSON.stringify(info), 'EX', CACHE_TTL_SECONDS)
|
if (redisAvailable) {
|
||||||
|
await useRedis().set(cacheKey, JSON.stringify(info), 'EX', CACHE_TTL_SECONDS).catch(() => {})
|
||||||
|
}
|
||||||
return info
|
return info
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`[prefeitura] lookup falhou para '${dominio}':`, (err as Error).message)
|
console.error(`[prefeitura] lookup falhou para '${dominio}':`, (err as Error).message)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user