From e924e69bf38e2831edeb64365f9d0c3fcc53134b Mon Sep 17 00:00:00 2001 From: totregex Date: Mon, 6 Jan 2025 04:11:23 +0530 Subject: [PATCH] handle api errors gracefully --- src/components/Users/CreateUserForm.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/Users/CreateUserForm.tsx b/src/components/Users/CreateUserForm.tsx index f564b58e081..fbded3b8c9b 100644 --- a/src/components/Users/CreateUserForm.tsx +++ b/src/components/Users/CreateUserForm.tsx @@ -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({