@@ -10,7 +10,7 @@ const getUser = async (
1010 setIsLoading ?: SetStateCallback < boolean > ,
1111 setUser ?: ( user : PublicUser ) => void ,
1212 setAuth ?: SetStateCallback < boolean > ,
13- setIsError ?: SetStateCallback < boolean > ,
13+ setErrorMessage ?: SetStateCallback < string > ,
1414 id : string | null = null ,
1515) : Promise < void > => {
1616 let url = `${ API_BASE } /api/auth/profile` ;
@@ -26,10 +26,13 @@ const getUser = async (
2626 setIsLoading ?.( false ) ;
2727 } catch ( error ) {
2828 const axiosError = error as AxiosError ;
29- if ( axiosError . response ?. status === 401 ) {
29+ const status = axiosError . response ?. status ;
30+ if ( status === 401 ) {
3031 setAuth ?.( false ) ;
32+ setErrorMessage ?.( processAuthError ( axiosError ) ) ;
3133 } else {
32- setIsError ?.( true ) ;
34+ const msg = ( axiosError . response ?. data as any ) ?. message ?? 'Unknown error' ;
35+ setErrorMessage ?.( `Error fetching user: ${ status } ${ msg } ` ) ;
3336 }
3437 setIsLoading ?.( false ) ;
3538 }
@@ -50,32 +53,33 @@ const getUsers = async (
5053 ) ;
5154 setUsers ( response . data ) ;
5255 } catch ( error ) {
53- if ( axios . isAxiosError ( error ) ) {
54- if ( error . response ?. status === 401 ) {
55- setAuth ( false ) ;
56- setErrorMessage ( processAuthError ( error ) ) ;
57- } else {
58- const msg = ( error . response ?. data as any ) ?. message ?? error . message ;
59- setErrorMessage ( `Error fetching users: ${ msg } ` ) ;
60- }
56+ const axiosError = error as AxiosError ;
57+ const status = axiosError . response ?. status ;
58+ if ( status === 401 ) {
59+ setAuth ( false ) ;
60+ setErrorMessage ( processAuthError ( axiosError ) ) ;
6161 } else {
62- setErrorMessage ( `Error fetching users: ${ ( error as Error ) . message ?? 'Unknown error' } ` ) ;
62+ const msg = ( axiosError . response ?. data as any ) ?. message ?? 'Unknown error' ;
63+ setErrorMessage ( `Error fetching users: ${ status } ${ msg } ` ) ;
6364 }
6465 } finally {
6566 setIsLoading ( false ) ;
6667 }
6768} ;
6869
69- const updateUser = async ( user : PublicUser ) : Promise < void > => {
70- console . log ( user ) ;
70+ const updateUser = async (
71+ user : PublicUser ,
72+ setErrorMessage : SetStateCallback < string > ,
73+ setIsLoading : SetStateCallback < boolean > ,
74+ ) : Promise < void > => {
7175 try {
7276 await axios . post ( `${ API_BASE } /api/auth/gitAccount` , user , getAxiosConfig ( ) ) ;
7377 } catch ( error ) {
7478 const axiosError = error as AxiosError ;
75- if ( axiosError . response ) {
76- console . log ( ( axiosError . response . data as any ) . message ) ;
77- }
78- throw error ;
79+ const status = axiosError . response ?. status ;
80+ const msg = ( axiosError . response ? .data as any ) ? .message ?? 'Unknown error' ;
81+ setErrorMessage ( `Error updating user: ${ status } ${ msg } ` ) ;
82+ setIsLoading ( false ) ;
7983 }
8084} ;
8185
0 commit comments