mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-02 06:20:29 +00:00
fix(app): normalize oauth error messages
This commit is contained in:
parent
70303d0b42
commit
ff3b174c42
1 changed files with 21 additions and 4 deletions
|
|
@ -103,6 +103,24 @@ export function DialogConnectProvider(props: { provider: string }) {
|
||||||
return value.label ?? ""
|
return value.label ?? ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatError(value: unknown, fallback: string): string {
|
||||||
|
if (value && typeof value === "object" && "data" in value) {
|
||||||
|
const data = (value as { data?: { message?: unknown } }).data
|
||||||
|
if (typeof data?.message === "string" && data.message) return data.message
|
||||||
|
}
|
||||||
|
if (value && typeof value === "object" && "error" in value) {
|
||||||
|
const nested = formatError((value as { error?: unknown }).error, "")
|
||||||
|
if (nested) return nested
|
||||||
|
}
|
||||||
|
if (value && typeof value === "object" && "message" in value) {
|
||||||
|
const message = (value as { message?: unknown }).message
|
||||||
|
if (typeof message === "string" && message) return message
|
||||||
|
}
|
||||||
|
if (value instanceof Error && value.message) return value.message
|
||||||
|
if (typeof value === "string" && value) return value
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
|
||||||
async function selectMethod(index: number) {
|
async function selectMethod(index: number) {
|
||||||
if (timer.current !== undefined) {
|
if (timer.current !== undefined) {
|
||||||
clearTimeout(timer.current)
|
clearTimeout(timer.current)
|
||||||
|
|
@ -141,7 +159,7 @@ export function DialogConnectProvider(props: { provider: string }) {
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
if (!alive.value) return
|
if (!alive.value) return
|
||||||
dispatch({ type: "auth.error", error: String(e) })
|
dispatch({ type: "auth.error", error: formatError(e, language.t("common.requestFailed")) })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -328,8 +346,7 @@ export function DialogConnectProvider(props: { provider: string }) {
|
||||||
await complete()
|
await complete()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const message = result.error instanceof Error ? result.error.message : String(result.error)
|
setFormStore("error", formatError(result.error, language.t("provider.connect.oauth.code.invalid")))
|
||||||
setFormStore("error", message || language.t("provider.connect.oauth.code.invalid"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -385,7 +402,7 @@ export function DialogConnectProvider(props: { provider: string }) {
|
||||||
if (!alive.value) return
|
if (!alive.value) return
|
||||||
|
|
||||||
if (!result.ok) {
|
if (!result.ok) {
|
||||||
const message = result.error instanceof Error ? result.error.message : String(result.error)
|
const message = formatError(result.error, language.t("common.requestFailed"))
|
||||||
dispatch({ type: "auth.error", error: message })
|
dispatch({ type: "auth.error", error: message })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue