Merged in chore/add-error-details-for-sentry (pull request #3378)
Include more details when throwing errors for debugging in Sentry * WIP throw errors with more details for debugging in Sentry * Fix throwing response-data * Clearer message when a response fails * Add message to errors * better typings * . * Try to send profileID and membershipNumber to Sentry when we fail to parse the apiResponse * rename notFound -> notFoundError * Merge branch 'master' of bitbucket.org:scandic-swap/web into chore/add-error-details-for-sentry Approved-by: Linus Flood
This commit is contained in:
@@ -3,7 +3,7 @@ import { cache } from "react"
|
||||
import { createCounter } from "@scandic-hotels/common/telemetry"
|
||||
|
||||
import { router } from "../../.."
|
||||
import { notFound } from "../../../errors"
|
||||
import { notFoundError } from "../../../errors"
|
||||
import { GetContactConfig } from "../../../graphql/Query/ContactConfig.graphql"
|
||||
import { GetFooter, GetFooterRef } from "../../../graphql/Query/Footer.graphql"
|
||||
import { GetHeader, GetHeaderRef } from "../../../graphql/Query/Header.graphql"
|
||||
@@ -65,12 +65,12 @@ const getContactConfig = cache(async (lang: Lang) => {
|
||||
const metricsGetContactConfig = getContactConfigCounter.init({ lang })
|
||||
|
||||
metricsGetContactConfig.start()
|
||||
|
||||
const variables = {
|
||||
locale: lang,
|
||||
}
|
||||
const response = await request<ContactConfigData>(
|
||||
GetContactConfig,
|
||||
{
|
||||
locale: lang,
|
||||
},
|
||||
variables,
|
||||
{
|
||||
key: `${lang}:contact`,
|
||||
ttl: "max",
|
||||
@@ -78,9 +78,11 @@ const getContactConfig = cache(async (lang: Lang) => {
|
||||
)
|
||||
|
||||
if (!response.data) {
|
||||
const notFoundError = notFound(response)
|
||||
metricsGetContactConfig.noDataError()
|
||||
throw notFoundError
|
||||
throw notFoundError({
|
||||
message: "GetContactConfig returned no data",
|
||||
errorDetails: variables,
|
||||
})
|
||||
}
|
||||
|
||||
const verifiedData = validateContactConfigSchema.safeParse(response.data)
|
||||
@@ -109,21 +111,18 @@ export const baseQueryRouter = router({
|
||||
|
||||
metricsGetHeaderRefs.start()
|
||||
|
||||
const responseRef = await request<GetHeaderRefs>(
|
||||
GetHeaderRef,
|
||||
{
|
||||
locale: lang,
|
||||
},
|
||||
{
|
||||
key: generateRefsResponseTag(lang, "header"),
|
||||
ttl: "max",
|
||||
}
|
||||
)
|
||||
const variables = { locale: lang }
|
||||
const responseRef = await request<GetHeaderRefs>(GetHeaderRef, variables, {
|
||||
key: generateRefsResponseTag(lang, "header"),
|
||||
ttl: "max",
|
||||
})
|
||||
|
||||
if (!responseRef.data) {
|
||||
const notFoundError = notFound(responseRef)
|
||||
metricsGetHeaderRefs.noDataError()
|
||||
throw notFoundError
|
||||
throw notFoundError({
|
||||
message: "GetHeaderRef returned no data",
|
||||
errorDetails: variables,
|
||||
})
|
||||
}
|
||||
|
||||
const validatedHeaderRefs = headerRefsSchema.safeParse(responseRef.data)
|
||||
@@ -147,16 +146,17 @@ export const baseQueryRouter = router({
|
||||
generateTag(lang, validatedHeaderRefs.data.header.system.uid),
|
||||
].flat()
|
||||
|
||||
const response = await request<GetHeaderData>(
|
||||
GetHeader,
|
||||
{ locale: lang },
|
||||
{ key: tags, ttl: "max" }
|
||||
)
|
||||
const response = await request<GetHeaderData>(GetHeader, variables, {
|
||||
key: tags,
|
||||
ttl: "max",
|
||||
})
|
||||
|
||||
if (!response.data) {
|
||||
const notFoundError = notFound(response)
|
||||
metricsGetHeader.noDataError()
|
||||
throw notFoundError
|
||||
throw notFoundError({
|
||||
message: "GetHeader returned no data",
|
||||
errorDetails: variables,
|
||||
})
|
||||
}
|
||||
|
||||
const validatedHeaderConfig = headerSchema.safeParse(response.data)
|
||||
@@ -182,11 +182,10 @@ export const baseQueryRouter = router({
|
||||
|
||||
metricsGetFooterRefs.start()
|
||||
|
||||
const variables = { locale: lang }
|
||||
const responseRef = await request<FooterRefDataRaw>(
|
||||
GetFooterRef,
|
||||
{
|
||||
locale: lang,
|
||||
},
|
||||
variables,
|
||||
{
|
||||
key: generateRefsResponseTag(lang, "footer"),
|
||||
ttl: "max",
|
||||
@@ -194,9 +193,11 @@ export const baseQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!responseRef.data) {
|
||||
const notFoundError = notFound(responseRef)
|
||||
metricsGetFooterRefs.noDataError()
|
||||
throw notFoundError
|
||||
throw notFoundError({
|
||||
message: "GetFooterRef returned no data",
|
||||
errorDetails: variables,
|
||||
})
|
||||
}
|
||||
|
||||
const validatedFooterRefs = validateFooterRefConfigSchema.safeParse(
|
||||
@@ -223,21 +224,17 @@ export const baseQueryRouter = router({
|
||||
generateTag(lang, footerUID),
|
||||
].flat()
|
||||
|
||||
const response = await request<FooterDataRaw>(
|
||||
GetFooter,
|
||||
{
|
||||
locale: lang,
|
||||
},
|
||||
{
|
||||
key: tags,
|
||||
ttl: "max",
|
||||
}
|
||||
)
|
||||
const response = await request<FooterDataRaw>(GetFooter, variables, {
|
||||
key: tags,
|
||||
ttl: "max",
|
||||
})
|
||||
|
||||
if (!response.data) {
|
||||
const notFoundError = notFound(response)
|
||||
metricsGetFooter.noDataError()
|
||||
throw notFoundError
|
||||
throw notFoundError({
|
||||
message: "GetFooter returned no data",
|
||||
errorDetails: variables,
|
||||
})
|
||||
}
|
||||
|
||||
const validatedFooterConfig = validateFooterConfigSchema.safeParse(
|
||||
@@ -269,9 +266,10 @@ export const baseQueryRouter = router({
|
||||
|
||||
metricsGetSitewideCampaignBannerRefs.start()
|
||||
|
||||
const refVariables = { locale: lang }
|
||||
const responseRef = await request<GetSitewideCampaignBannerRefData>(
|
||||
GetSitewideCampaignBannerRef,
|
||||
{ locale: lang },
|
||||
refVariables,
|
||||
{
|
||||
key: generateRefsResponseTag(lang, "sitewide_campaign_banner"),
|
||||
ttl: "max",
|
||||
@@ -279,9 +277,11 @@ export const baseQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!responseRef.data) {
|
||||
const notFoundError = notFound(responseRef)
|
||||
metricsGetSitewideCampaignBannerRefs.noDataError()
|
||||
throw notFoundError
|
||||
throw notFoundError({
|
||||
message: "GetSitewideCampaignBannerRef returned no data",
|
||||
errorDetails: refVariables,
|
||||
})
|
||||
}
|
||||
|
||||
const validatedSitewideCampaignBannerRef =
|
||||
@@ -312,17 +312,21 @@ export const baseQueryRouter = router({
|
||||
|
||||
metricsGetSitewideCampaignBanner.start()
|
||||
|
||||
const variables = { locale: lang }
|
||||
const sitewideCampaignBannerResponse =
|
||||
await request<GetSitewideCampaignBannerData>(
|
||||
GetSitewideCampaignBanner,
|
||||
{ locale: lang },
|
||||
variables,
|
||||
{ key: tags, ttl: "max" }
|
||||
)
|
||||
|
||||
if (!sitewideCampaignBannerResponse.data) {
|
||||
const notFoundError = notFound(sitewideCampaignBannerResponse)
|
||||
metricsGetSitewideCampaignBanner.noDataError()
|
||||
throw notFoundError
|
||||
|
||||
throw notFoundError({
|
||||
message: "GetSitewideCampaignBanner returned no data",
|
||||
errorDetails: variables,
|
||||
})
|
||||
}
|
||||
|
||||
const validatedSitewideCampaignBanner =
|
||||
@@ -354,11 +358,12 @@ export const baseQueryRouter = router({
|
||||
|
||||
metricsGetSiteConfigRefs.start()
|
||||
|
||||
const refVariables = {
|
||||
locale: lang,
|
||||
}
|
||||
const responseRef = await request<GetSiteConfigRefData>(
|
||||
GetSiteConfigRef,
|
||||
{
|
||||
locale: lang,
|
||||
},
|
||||
refVariables,
|
||||
{
|
||||
key: generateRefsResponseTag(lang, "site_config"),
|
||||
ttl: "max",
|
||||
@@ -366,9 +371,11 @@ export const baseQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!responseRef.data) {
|
||||
const notFoundError = notFound(responseRef)
|
||||
metricsGetSiteConfigRefs.noDataError()
|
||||
throw notFoundError
|
||||
throw notFoundError({
|
||||
message: "SiteConfigRefs returned no data",
|
||||
errorDetails: refVariables,
|
||||
})
|
||||
}
|
||||
|
||||
const validatedSiteConfigRef = siteConfigRefSchema.safeParse(
|
||||
@@ -397,24 +404,21 @@ export const baseQueryRouter = router({
|
||||
|
||||
metricsGetSiteConfig.start()
|
||||
|
||||
const variables = { locale: lang }
|
||||
const [siteConfigResponse, contactConfig] = await Promise.all([
|
||||
request<GetSiteConfigData>(
|
||||
GetSiteConfig,
|
||||
{
|
||||
locale: lang,
|
||||
},
|
||||
{
|
||||
key: tags,
|
||||
ttl: "max",
|
||||
}
|
||||
),
|
||||
request<GetSiteConfigData>(GetSiteConfig, variables, {
|
||||
key: tags,
|
||||
ttl: "max",
|
||||
}),
|
||||
getContactConfig(lang),
|
||||
])
|
||||
|
||||
if (!siteConfigResponse.data) {
|
||||
const notFoundError = notFound(siteConfigResponse)
|
||||
metricsGetSiteConfig.noDataError()
|
||||
throw notFoundError
|
||||
throw notFoundError({
|
||||
message: "SiteConfig returned no data",
|
||||
errorDetails: variables,
|
||||
})
|
||||
}
|
||||
|
||||
const validatedSiteConfig = siteConfigSchema.safeParse(
|
||||
|
||||
Reference in New Issue
Block a user