@@ -5,21 +5,22 @@ const baseUrl = import.meta.env.VITE_API_URI
55 ? `${ import . meta. env . VITE_API_URI } /api/v1`
66 : `${ location . origin } /api/v1` ;
77
8- const getPush = async ( id , setIsLoading , setData , setAuth , setIsError ) => {
9- const url = `${ baseUrl } /push/${ id } ` ;
10- await axios ( url , getAxiosConfig ( ) )
11- . then ( ( response ) => {
8+ const getPush = async ( id , setIsLoading , setData , setAuth , setIsError ) => {
9+ const url = `${ baseUrl } /push/${ id } ` ;
10+ setIsLoading ( true ) ;
11+
12+ try {
13+ const response = await axios ( url , getAxiosConfig ( ) ) ;
1214 const data = response . data ;
1315 data . diff = data . steps . find ( ( x ) => x . stepName === 'diff' ) ;
1416 setData ( data ) ;
15- setIsLoading ( false ) ;
16- } )
17- . catch ( ( error ) => {
18- if ( error . response && error . response . status === 401 ) setAuth ( false ) ;
17+ } catch ( error ) {
18+ if ( error . response ?. status === 401 ) setAuth ( false ) ;
1919 else setIsError ( true ) ;
20+ } finally {
2021 setIsLoading ( false ) ;
21- } ) ;
22- } ;
22+ }
23+ } ;
2324
2425const getPushes = async (
2526 setIsLoading ,
@@ -32,28 +33,29 @@ const getPushes = async (
3233 canceled : false ,
3334 authorised : false ,
3435 rejected : false ,
35- } ,
36+ }
3637) => {
3738 const url = new URL ( `${ baseUrl } /push` ) ;
3839 url . search = new URLSearchParams ( query ) ;
3940
4041 setIsLoading ( true ) ;
41- await axios ( url . toString ( ) , getAxiosConfig ( ) )
42- . then ( ( response ) => {
43- const data = response . data ;
44- setData ( data ) ;
45- } )
46- . catch ( ( error ) => {
47- setIsError ( true ) ;
48- if ( error . response && error . response . status === 401 ) {
49- setAuth ( false ) ;
50- setErrorMessage ( processAuthError ( error ) ) ;
51- } else {
52- setErrorMessage ( `Error fetching pushes: ${ error . response . data . message } ` ) ;
53- }
54- } ) . finally ( ( ) => {
55- setIsLoading ( false ) ;
56- } ) ;
42+
43+ try {
44+ const response = await axios ( url . toString ( ) , getAxiosConfig ( ) ) ;
45+ setData ( response . data ) ;
46+ } catch ( error ) {
47+ setIsError ( true ) ;
48+
49+ if ( error . response ?. status === 401 ) {
50+ setAuth ( false ) ;
51+ setErrorMessage ( processAuthError ( error ) ) ;
52+ } else {
53+ const message = error . response ?. data ?. message || error . message ;
54+ setErrorMessage ( `Error fetching pushes: ${ message } ` ) ;
55+ }
56+ } finally {
57+ setIsLoading ( false ) ;
58+ }
5759} ;
5860
5961const authorisePush = async ( id , setMessage , setUserAllowedToApprove , attestation ) => {
0 commit comments