I want to return error from react-query mutation service hook I've created here
const getMutationService = () => {
return {
editProfile: async (
displayName: string,
privateProfile?: boolean,
): Promise<AuthEditMeResponse | undefined> => {
try {
const result = await userApi.mePost({
payload: {
display_name: displayName,
_private: privateProfile,
},
});
return result;
} catch (error) {
console.log("User Edit Profile Error", error);
}
},
};
};
const useUserProfile = () => {
const queryClient = useQueryClient();
const queryService = getQueryService();
// const { data, isLoading } = useQuery('auth', queryService.login)
const mutationService = getMutationService();
const editProfileData = async (
displayName: string,
privateProfile?: boolean,
): Promise<AuthEditMeResponse | void> => {
try {
return await mutationService.editProfile(displayName, privateProfile);
} catch (error) {
console.log(error);
}
};
return editProfileData;
};
export default useUserProfile;
Right now I am only returning the result, which is the successful result, however the API endpoint I am requesting to also returns error status codes that I must need and use for my front end component.
How can I return isLoading, data, or error from this getMutationService hook i've created? Instead currently its only returning successful responses to my component.