@@ -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 }
@@ -328,8 +346,7 @@ export function DialogConnectProvider(props: { provider: string }) {
328346 await complete ( )
329347 return
330348 }
331- const message = result . error instanceof Error ? result . error . message : String ( result . error )
332- setFormStore ( "error" , message || language . t ( "provider.connect.oauth.code.invalid" ) )
349+ setFormStore ( "error" , formatError ( result . error , language . t ( "provider.connect.oauth.code.invalid" ) ) )
333350 }
334351
335352 return (
@@ -385,7 +402,7 @@ export function DialogConnectProvider(props: { provider: string }) {
385402 if ( ! alive . value ) return
386403
387404 if ( ! result . ok ) {
388- const message = result . error instanceof Error ? result . error . message : String ( result . error )
405+ const message = formatError ( result . error , language . t ( "common.requestFailed" ) )
389406 dispatch ( { type : "auth.error" , error : message } )
390407 return
391408 }
0 commit comments