Show better error messages
This commit is contained in:
@@ -8,13 +8,20 @@ export function useSignup(){
|
||||
return useMutation({
|
||||
mutationKey: ["signup"],
|
||||
mutationFn: async (account: Account) => {
|
||||
const response = await api.post("/auth/signup", account);
|
||||
try{
|
||||
const response = await api.post("/auth/signup", account);
|
||||
|
||||
if(response.status !== 200){
|
||||
throw new Error("Failed to signup");
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
else if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user