@@ -47,26 +47,31 @@ export const useIframe = () => {
4747 url += `${ separator } client=electron` ;
4848 }
4949
50- const result = await fetch ( apiUrl , {
51- method : apiMethod ,
52- headers : undefined ,
53- credentials : 'include' ,
54- } ) ;
50+ try {
51+ const result = await fetch ( apiUrl , {
52+ method : apiMethod ,
53+ headers : undefined ,
54+ credentials : 'include' ,
55+ } ) ;
5556
56- if ( ! result . ok || result . status !== 200 ) {
57- setIframeLoginUrl ( url ) ;
58- callback ?.( new Error ( ) , null ) ;
59- return ;
60- }
61-
62- loginWithToken ( await result . json ( ) , async ( error : Meteor . Error | Meteor . TypedError | Error | null | undefined ) => {
63- if ( error ) {
57+ if ( ! result . ok || result . status !== 200 ) {
6458 setIframeLoginUrl ( url ) ;
65- } else {
66- setIframeLoginUrl ( undefined ) ;
59+ callback ?. ( new Error ( ) , null ) ;
60+ return ;
6761 }
68- callback ?.( error , await result . json ( ) ) ;
69- } ) ;
62+
63+ loginWithToken ( await result . json ( ) , async ( error : Meteor . Error | Meteor . TypedError | Error | null | undefined ) => {
64+ if ( error ) {
65+ setIframeLoginUrl ( url ) ;
66+ } else {
67+ setIframeLoginUrl ( undefined ) ;
68+ }
69+ callback ?.( error , await result . json ( ) ) ;
70+ } ) ;
71+ } catch ( error ) {
72+ setIframeLoginUrl ( url ) ;
73+ callback ?.( error instanceof Error ? error : undefined , null ) ;
74+ }
7075 } ,
7176 [ apiMethod , apiUrl , accountIframeUrl , loginWithToken , enabled ] ,
7277 ) ;
0 commit comments