@@ -5,21 +5,22 @@ const baseUrl = import.meta.env.VITE_API_URI
5
5
? `${ import . meta. env . VITE_API_URI } /api/v1`
6
6
: `${ location . origin } /api/v1` ;
7
7
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 ( ) ) ;
12
14
const data = response . data ;
13
15
data . diff = data . steps . find ( ( x ) => x . stepName === 'diff' ) ;
14
16
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 ) ;
19
19
else setIsError ( true ) ;
20
+ } finally {
20
21
setIsLoading ( false ) ;
21
- } ) ;
22
- } ;
22
+ }
23
+ } ;
23
24
24
25
const getPushes = async (
25
26
setIsLoading ,
@@ -32,28 +33,29 @@ const getPushes = async (
32
33
canceled : false ,
33
34
authorised : false ,
34
35
rejected : false ,
35
- } ,
36
+ }
36
37
) => {
37
38
const url = new URL ( `${ baseUrl } /push` ) ;
38
39
url . search = new URLSearchParams ( query ) ;
39
40
40
41
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
+ }
57
59
} ;
58
60
59
61
const authorisePush = async ( id , setMessage , setUserAllowedToApprove , attestation ) => {
0 commit comments