Merged in fix/warmup-not-throwing (pull request #3179)
fix: warmup threw error * fix: warmup threw error * . Approved-by: Linus Flood
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
import { createLogger } from "@scandic-hotels/common/logger/createLogger"
|
||||
|
||||
import type { Lang } from "@scandic-hotels/common/constants/language"
|
||||
|
||||
export async function warmupHotelDataOnLang(lang: Lang) {
|
||||
const warmupHotelDataOnLangLogger = createLogger("warmupHotelDataOnLang")
|
||||
const PUBLIC_URL = Netlify.env.get("PUBLIC_URL")
|
||||
|
||||
warmupHotelDataOnLangLogger.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()
|
||||
warmupHotelDataOnLangLogger.info(
|
||||
`[WARMUP] Retrieved ${hotels.length} hotels.`
|
||||
)
|
||||
} catch (error) {
|
||||
warmupHotelDataOnLangLogger.error(
|
||||
`[WARMUP] Error warming cache with hoteldata on language ${lang} with error: ${error}`
|
||||
)
|
||||
}
|
||||
}
|
||||
21
apps/scandic-web/netlify/utils/initSentry.ts
Normal file
21
apps/scandic-web/netlify/utils/initSentry.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import Sentry from "@sentry/nextjs"
|
||||
|
||||
export const denyUrls: (string | RegExp)[] = [
|
||||
// Ignore preview urls
|
||||
/\/.{2}\/preview\//,
|
||||
]
|
||||
|
||||
export const onRequestError = Sentry.captureRequestError
|
||||
|
||||
export async function configureSentry() {
|
||||
const sentryEnvironment = Netlify.env.get("SENTRY_ENVIRONMENT")
|
||||
const sampleRate = Number(Netlify.env.get("SENTRY_SERVER_SAMPLERATE") ?? 0.01)
|
||||
Sentry.init({
|
||||
dsn: "https://fe39c070b4154e2f9cc35f0e5de0aedb@o4508102497206272.ingest.de.sentry.io/4508102500286544",
|
||||
environment: sentryEnvironment,
|
||||
enabled: sentryEnvironment !== "development",
|
||||
tracesSampleRate: sampleRate,
|
||||
denyUrls: denyUrls,
|
||||
enableLogs: true,
|
||||
})
|
||||
}
|
||||
11
apps/scandic-web/netlify/utils/safeTry.ts
Normal file
11
apps/scandic-web/netlify/utils/safeTry.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export type SafeTryResult<T> = Promise<
|
||||
[T, undefined] | [undefined, Error | unknown]
|
||||
>
|
||||
|
||||
export async function safeTry<T>(func: Promise<T>): SafeTryResult<T> {
|
||||
try {
|
||||
return [await func, undefined] as const
|
||||
} catch (err) {
|
||||
return [undefined, err instanceof Error ? err : (err as unknown)] as const
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user