T
TanStack3y ago
robust-apricot

Error from axios how to handle it

Here is the mutation query
export const createWorkspaceMutation = async (data: createWorkspaceFormData): Promise<createWorkspaceApiResponse> => {
const response = await axiosinstance.post<createWorkspaceApiResponse>("/api/createworkspace", data);
return response.data;
};
export const createWorkspaceMutation = async (data: createWorkspaceFormData): Promise<createWorkspaceApiResponse> => {
const response = await axiosinstance.post<createWorkspaceApiResponse>("/api/createworkspace", data);
return response.data;
};
if i get a 401 in response, how to handle that, does it will be get caught by react query or i have to handle it within the mutation function.. im confused a bit about this...
4 Replies
fair-rose
fair-rose3y ago
Did you read the documentation of useMutation?
robust-apricot
robust-apricotOP3y ago
@M00LTi i did This function will fire if the mutation encounters an error and will be passed the error. means if promise get reject or throw an error, error will be triggered
fair-rose
fair-rose3y ago
Does this answer your question?
robust-apricot
robust-apricotOP3y ago
Yes

Did you find this page helpful?