diff --git a/apps/scandic-web/app/[lang]/(partner)/(sas)/(protected)/sas-x-scandic/otp/page.tsx b/apps/scandic-web/app/[lang]/(partner)/(sas)/(protected)/sas-x-scandic/otp/page.tsx index 23dd6c989..968f05899 100644 --- a/apps/scandic-web/app/[lang]/(partner)/(sas)/(protected)/sas-x-scandic/otp/page.tsx +++ b/apps/scandic-web/app/[lang]/(partner)/(sas)/(protected)/sas-x-scandic/otp/page.tsx @@ -190,7 +190,12 @@ async function handleLinkAccount({ url: `/${lang}/sas-x-scandic/error?errorCode=dateOfBirthMismatch`, type: "replace", } + // Currently unhandled errors + case "accountToNew": + case "nameNotMatched": + case "blockedForRelink": case "error": + default: return { url: `/${lang}/sas-x-scandic/error`, type: "replace", diff --git a/apps/scandic-web/components/MyPages/SASLevelUpgradeCheck.tsx b/apps/scandic-web/components/MyPages/SASLevelUpgradeCheck.tsx index d3946e2c3..88d2bd2d0 100644 --- a/apps/scandic-web/components/MyPages/SASLevelUpgradeCheck.tsx +++ b/apps/scandic-web/components/MyPages/SASLevelUpgradeCheck.tsx @@ -24,7 +24,8 @@ export function SASLevelUpgradeCheck() { toast.success( intl.formatMessage( { - defaultMessage: "Your SAS level has upgraded you to {level}!", + defaultMessage: + "Your SAS EuroBonus level has upgraded you to {level}!", }, { level: TIER_TO_FRIEND_MAP[result.toLevel], diff --git a/apps/scandic-web/server/routers/partners/sas/linkAccount.ts b/apps/scandic-web/server/routers/partners/sas/linkAccount.ts index cc760b3d7..de752b024 100644 --- a/apps/scandic-web/server/routers/partners/sas/linkAccount.ts +++ b/apps/scandic-web/server/routers/partners/sas/linkAccount.ts @@ -11,6 +11,9 @@ const outputSchema = z.object({ "linked", "alreadyLinked", "dateOfBirthMismatch", + "nameNotMatched", + "blockedForRelink", + "accountToNew", "error", ]), }) @@ -48,11 +51,34 @@ export const linkAccount = protectedProcedure if (apiResponse.status === 400) { const result = await apiResponse.json() - if (result.errors?.some((x: any) => x.detail.includes("birth date"))) { - return { linkingState: "dateOfBirthMismatch" } + const data = badRequestSchema.safeParse(result) + if (!data.success) { + const linkAccountBadRequestSchemaError = `[SAS] failed to parse link account bad request schema ${JSON.stringify(data.error)}` + console.error(linkAccountBadRequestSchemaError) + Sentry.captureMessage(linkAccountBadRequestSchemaError) + return { linkingState: "error" } } console.log("[SAS] link account error with response", result) + + const { errors } = data.data + + if (errors.some((x) => x.code === "BirthDateNotMatched")) { + return { linkingState: "dateOfBirthMismatch" } + } + if (errors.some((x) => x.code === "BlockedForRelink")) { + return { linkingState: "blockedForRelink" } + } + if (errors.some((x) => x.code === "AccountToNew")) { + return { linkingState: "accountToNew" } + } + if (errors.some((x) => x.code === "NameNotMatched")) { + return { linkingState: "nameNotMatched" } + } + if (errors.some((x) => x.code === "AlreadyLinked")) { + return { linkingState: "alreadyLinked" } + } + return { linkingState: "error" } } @@ -69,3 +95,19 @@ export const linkAccount = protectedProcedure function getCurrentDateWithoutTime() { return new Date().toISOString().slice(0, 10) } + +const badRequestSchema = z.object({ + errors: z.array( + z.object({ + code: z.enum([ + "BirthDateNotMatched", + "NameNotMatched", + "AlreadyLinked", + "BlockedForRelink", + "AccountToNew", + "UnknownReason", + ]), + details: z.string().optional(), + }) + ), +})