@samitouri / QOSami-HFS / commits / 365110e5

admin: in case of network error, validation of forms could stop working

Massimo Melina committed Mar 22, 2025 at 12:42 UTC 365110e5435f19d395f8357707045df4c8f71285
1 file changed +11 -4
mui-grid-form/index.ts
+11 -4
@@ -218,10 +218,17 @@ export function Form<Values extends Dict>({
218 if (!f || isValidElement(f) || !f.k) continue
219 const { k } = f
220 const v = values?.[k]
221 - const err = await apis[k]?.getError?.(v, { values, fields })
222 - || await f.getError?.(v, { values, fields })
223 - || fieldExceptions[k]
224 - errs[k] = err || false
221 + let err: ReactNode
222 + try {
223 + err = await apis[k]?.getError?.(v, { values, fields })
224 + || await f.getError?.(v, { values, fields })
225 + || fieldExceptions[k]
226 + || false
227 + }
228 + catch(e) {
229 + err = String(e) // keep exception as error
230 + }
231 + errs[k] = err
232 if (!submitAfterValidation.current && k === validateUpTo.current) break
233 if (!mounted.current) return // abort
234 }