refactor(SW-360): improve error handling logic
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"use server"
|
||||
|
||||
import { redirect } from "next/navigation"
|
||||
import { z } from "zod"
|
||||
|
||||
import * as api from "@/lib/api"
|
||||
@@ -45,7 +46,7 @@ export const registerUser = profileServiceServerActionProcedure
|
||||
})
|
||||
)
|
||||
|
||||
return false
|
||||
return { success: false, error: "Validation error" }
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -57,7 +58,7 @@ export const registerUser = profileServiceServerActionProcedure
|
||||
})
|
||||
|
||||
if (!apiResponse.ok) {
|
||||
const text = apiResponse.text()
|
||||
const text = await apiResponse.text()
|
||||
console.error(
|
||||
"registerUser api error",
|
||||
JSON.stringify({
|
||||
@@ -69,14 +70,16 @@ export const registerUser = profileServiceServerActionProcedure
|
||||
},
|
||||
})
|
||||
)
|
||||
return false
|
||||
return { success: false, error: "API error" }
|
||||
}
|
||||
|
||||
const json = await apiResponse.json()
|
||||
console.log("json", json)
|
||||
|
||||
return true
|
||||
// TODO: Redirect to actual success page.
|
||||
redirect("/signup/success")
|
||||
} catch (error) {
|
||||
return false
|
||||
console.error("Unexpected error", error)
|
||||
return { success: false, error: "Unexpected error" }
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user