Show better error messages

This commit is contained in:
2025-03-23 11:47:10 -04:00
parent 3b738c337b
commit c5fbb1d83f
12 changed files with 1206 additions and 599 deletions

View File

@@ -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;
}
}
}
});