Skip to content

Commit e466abc

Browse files
committed
fix types error
1 parent d07a7f7 commit e466abc

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/components/AuthContext/AuthContext.tsx

+8-14
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export const AuthProvider: React.FC<IAuthProviderProps> = ({children}) => {
120120
fetchUserData();
121121
}, [fetchUserData]);
122122

123-
const handleError = (error: AxiosError | Error, fallbackMessage: string) => {
123+
const handleError = (error: AxiosError | Error | unknown, fallbackMessage: string) => {
124124
if (error instanceof AxiosError) {
125125
console.error(fallbackMessage, error.response?.data.message || error.message);
126126
alert(fallbackMessage + ': ' + (error.response?.data.message || 'Network error'));
@@ -162,10 +162,7 @@ export const AuthProvider: React.FC<IAuthProviderProps> = ({children}) => {
162162
alert('Login failed: ' + (response.data.message || 'Unknown error'));
163163
}
164164
} catch (error) {
165-
if (error instanceof AxiosError) {
166-
handleError(error, 'Login error');
167-
}
168-
165+
handleError(error, 'Login error');
169166
} finally {
170167
setIsLoading(false);
171168
}
@@ -186,9 +183,8 @@ export const AuthProvider: React.FC<IAuthProviderProps> = ({children}) => {
186183
}
187184
} catch (error) {
188185
setIsAuthenticated(false);
189-
if (error instanceof AxiosError) {
190-
handleError(error, 'Registration error');
191-
}
186+
handleError(error, 'Registration error');
187+
192188
} finally {
193189
setIsLoading(false);
194190
}
@@ -219,9 +215,8 @@ export const AuthProvider: React.FC<IAuthProviderProps> = ({children}) => {
219215
alert('Failed to update profile: ' + (response.data.message || 'Unknown error'));
220216
}
221217
} catch (error) {
222-
if (error instanceof AxiosError) {
223-
handleError(error, 'Failed to update profile');
224-
}
218+
handleError(error, 'Failed to update profile');
219+
225220
} finally {
226221
setIsLoading(false);
227222
}
@@ -242,9 +237,8 @@ export const AuthProvider: React.FC<IAuthProviderProps> = ({children}) => {
242237
alert('Failed to delete profile: ' + (response.data.message || 'Unknown error'));
243238
}
244239
} catch (error) {
245-
if (error instanceof AxiosError) {
246-
handleError(error, 'Delete profile error');
247-
}
240+
handleError(error, 'Delete profile error');
241+
248242
} finally {
249243
setIsLoading(false);
250244
}

0 commit comments

Comments
 (0)