feat(SW-3006): added default timeout to all requests * feat(sw-3006): added default timeout to all requests * Fixed spreading Approved-by: Joakim Jäderberg
32 lines
924 B
TypeScript
32 lines
924 B
TypeScript
import type { Lang } from "@/constants/languages"
|
|
|
|
export async function warmupHotelDataOnLang(lang: Lang) {
|
|
const PUBLIC_URL = Netlify.env.get("PUBLIC_URL")
|
|
console.info(
|
|
`[WARMUP] Started warmup cache hoteldata for language ${lang} at: ${new Date().toISOString()}!`
|
|
)
|
|
|
|
try {
|
|
const hotelsResponse = await fetch(
|
|
`${PUBLIC_URL}/api/hoteldata?lang=${lang}`,
|
|
{
|
|
headers: { cache: "no-store" },
|
|
signal: AbortSignal.timeout(30_000),
|
|
}
|
|
)
|
|
|
|
if (!hotelsResponse.ok) {
|
|
throw new Error(
|
|
`[WARMUP] Failed to warmup cache for hotels on language ${lang} with error: ${hotelsResponse.statusText}`
|
|
)
|
|
}
|
|
|
|
const hotels = await hotelsResponse.json()
|
|
console.info(`[WARMUP] Retrieved ${hotels.length} hotels.`)
|
|
} catch (error) {
|
|
console.error(
|
|
`[WARMUP] Error warming cache with hoteldata on language ${lang} with error: ${error}`
|
|
)
|
|
}
|
|
}
|