Merged in feat/sw-2526-update-sas-error-handling-after-api-changes (pull request #1886)
SW-2526 - Update error handling for link SAS account * Update error handling for link SAS account * Capture schema validation error and send to Sentry * Add cases for unhandled otp errors Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -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(),
|
||||
})
|
||||
),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user