Skip to content

Commit

Permalink
handle api errors gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
rajku-dev committed Jan 5, 2025
1 parent ababd0d commit e924e69
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/components/Users/CreateUserForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,17 @@ export default function CreateUserForm({ onSubmitSuccess }: Props) {
});
onSubmitSuccess?.(user!);
} else {
Notification.Error({
msg: error?.message ?? t("user_add_error"),
});
if (error) {
const errors = (error.errors as any[]) || [];

errors.forEach((err) => {
const field = err.loc[0];
form.setError(field, { message: err.msg });
Notification.Error({
msg: err.msg,
});
});
}
}
} catch (error) {
Notification.Error({
Expand Down

0 comments on commit e924e69

Please sign in to comment.