Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6581

React Query is not cathcing Axios error in React Native

$
0
0

I have a react native expo typescript project and I'm doing authentication. I have axios function:

export type LoginData = {    email: string;    password: string;}export const loggInUser = async (data: LoginData): Promise<User> => {    const response = await axiosClient.post<Promise<User>>('/login', data);    return response.data;    }

And inside my Login component I have:

 const {         mutate: loginUser, isLoading     } = useMutation(        (userData: LoginData) => loggInUser(userData),        {            onSuccess: (data) => {                stateLoggIn(data);            },            onError(error: any) {                     setErrorMsg((error.response && error.response.data && error.response.data.message) || error.message || error.toString());            }        }       );

When the axios promise returns error, for instance 400, I am shown a react native warning for uncatched error. I tried to implement tryCatch inside axios function but then my onError case inside mutation wont ever fire off.

enter image description here

This is the react native expo warning


Viewing all articles
Browse latest Browse all 6581

Latest Images

Trending Articles



Latest Images