Merged in feat/sas-otp-error-handling (pull request #1272)

Feat/sas otp error handling

* Improve error handling for SAS OTP
* Remove failing and deprecated test

Approved-by: Joakim Jäderberg
This commit is contained in:
Anton Gunnarsson
2025-02-07 14:18:00 +00:00
parent fbe05eb456
commit 18288cb849
11 changed files with 187 additions and 94 deletions

View File

@@ -18,7 +18,16 @@ import type { OtpState } from "../getOTPState"
const inputSchema = z.object({})
const outputSchema = z.object({
status: z.string(),
status: z.enum([
"VERIFIED",
"ABUSED",
"EXPIRED",
"PENDING",
"RETRY",
"SENT",
"NULL",
"NOTSENT",
]),
referenceId: z.string().uuid(),
databaseUUID: z.string().uuid(),
otpExpiration: z.number(),
@@ -42,14 +51,15 @@ export const requestOtp = protectedProcedure
tokenResponse.status,
tokenResponse.statusText
)
if (!tokenResponse.ok) {
const errorBody = await tokenResponse.json()
console.error("[SAS] requestOtp error", errorBody)
throw createError(errorBody)
}
const parseResult = outputSchema.safeParse(await tokenResponse.json())
const body = await tokenResponse.json()
const parseResult = outputSchema.safeParse(body)
if (!parseResult.success) {
console.error("[SAS] requestOtp error", body)
if (!tokenResponse.ok) {
throw createError(body)
}
throw createError(parseResult.error)
}