@@ -103,6 +103,24 @@ export function DialogConnectProvider(props: { provider: string }) {
103103 return value . label ?? ""
104104 }
105105
106+ function formatError ( value : unknown , fallback : string ) : string {
107+ if ( value && typeof value === "object" && "data" in value ) {
108+ const data = ( value as { data ?: { message ?: unknown } } ) . data
109+ if ( typeof data ?. message === "string" && data . message ) return data . message
110+ }
111+ if ( value && typeof value === "object" && "error" in value ) {
112+ const nested = formatError ( ( value as { error ?: unknown } ) . error , "" )
113+ if ( nested ) return nested
114+ }
115+ if ( value && typeof value === "object" && "message" in value ) {
116+ const message = ( value as { message ?: unknown } ) . message
117+ if ( typeof message === "string" && message ) return message
118+ }
119+ if ( value instanceof Error && value . message ) return value . message
120+ if ( typeof value === "string" && value ) return value
121+ return fallback
122+ }
123+
106124 async function selectMethod ( index : number ) {
107125 if ( timer . current !== undefined ) {
108126 clearTimeout ( timer . current )
@@ -141,7 +159,7 @@ export function DialogConnectProvider(props: { provider: string }) {
141159 } )
142160 . catch ( ( e ) => {
143161 if ( ! alive . value ) return
144- dispatch ( { type : "auth.error" , error : String ( e ) } )
162+ dispatch ( { type : "auth.error" , error : formatError ( e , language . t ( "common.requestFailed" ) ) } )
145163 } )
146164 }
147165 }
@@ -330,8 +348,7 @@ export function DialogConnectProvider(props: { provider: string }) {
330348 await complete ( )
331349 return
332350 }
333- const message = result . error instanceof Error ? result . error . message : String ( result . error )
334- setFormStore ( "error" , message || language . t ( "provider.connect.oauth.code.invalid" ) )
351+ setFormStore ( "error" , formatError ( result . error , language . t ( "provider.connect.oauth.code.invalid" ) ) )
335352 }
336353
337354 return (
@@ -387,7 +404,7 @@ export function DialogConnectProvider(props: { provider: string }) {
387404 if ( ! alive . value ) return
388405
389406 if ( ! result . ok ) {
390- const message = result . error instanceof Error ? result . error . message : String ( result . error )
407+ const message = formatError ( result . error , language . t ( "common.requestFailed" ) )
391408 dispatch ( { type : "auth.error" , error : message } )
392409 return
393410 }
0 commit comments