developer #4

Open
gabrielb wants to merge 20 commits from developer into main
Showing only changes of commit b638af1a39 - Show all commits

View File

@ -17,6 +17,8 @@ export async function fetchPrefeituraInfo(dominio: string): Promise<PrefeituraIn
if (!dominio) return null if (!dominio) return null
const cacheKey = `prefeitura:${dominio}` const cacheKey = `prefeitura:${dominio}`
let redisAvailable = true
try {
const cached = await useRedis().get(cacheKey) const cached = await useRedis().get(cacheKey)
if (cached) { if (cached) {
try { try {
@ -25,6 +27,9 @@ export async function fetchPrefeituraInfo(dominio: string): Promise<PrefeituraIn
// cache corrompido — segue para refetch // cache corrompido — segue para refetch
} }
} }
} catch {
redisAvailable = false
}
const cfg = useRuntimeConfig() const cfg = useRuntimeConfig()
try { try {
@ -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)