Merged in fix/sw-1664-sas-link-otp-error-handling (pull request #1354)
Update SAS OTP error handling Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { TRPCError } from "@trpc/server"
|
||||
import { cookies } from "next/headers"
|
||||
import { z } from "zod"
|
||||
|
||||
import { env } from "@/env/server"
|
||||
@@ -27,7 +26,7 @@ const outputSchema = z.object({
|
||||
"NULL",
|
||||
"NOTSENT",
|
||||
]),
|
||||
referenceId: z.string().uuid(),
|
||||
referenceId: z.string().uuid().optional(),
|
||||
databaseUUID: z.string().uuid().optional(),
|
||||
})
|
||||
|
||||
@@ -47,19 +46,27 @@ export const verifyOtp = protectedProcedure
|
||||
verifyResponse.status,
|
||||
verifyResponse.statusText
|
||||
)
|
||||
if (!verifyResponse.ok) {
|
||||
const errorBody = await verifyResponse.json()
|
||||
console.error("[SAS] verifyOTP error", errorBody)
|
||||
throw createError(errorBody)
|
||||
|
||||
if (verifyResponse.status > 499) {
|
||||
console.error("[SAS] verifyOTP error", await verifyResponse.text())
|
||||
throw new TRPCError({
|
||||
code: "SERVICE_UNAVAILABLE",
|
||||
message: "Error from downstream SAS service",
|
||||
})
|
||||
}
|
||||
|
||||
const data = await verifyResponse.json()
|
||||
console.log("[SAS] verifyOTP data", data)
|
||||
const result = outputSchema.safeParse(data)
|
||||
if (!result.success) {
|
||||
console.error("[SAS] verifyOTP error", result.error)
|
||||
throw createError(data)
|
||||
}
|
||||
|
||||
console.log("[SAS] verifyOTP success")
|
||||
const verifyData = await verifyResponse.json()
|
||||
console.log("[SAS] verifyOTP data", verifyData)
|
||||
const response = outputSchema.parse(verifyData)
|
||||
console.log("[SAS] verifyOTP responding", response)
|
||||
console.log("[SAS] verifyOTP responding", result.data)
|
||||
|
||||
return response
|
||||
return result.data
|
||||
})
|
||||
|
||||
async function fetchVerifyOtp(input: z.infer<typeof inputSchema>) {
|
||||
|
||||
Reference in New Issue
Block a user