(zodError: ZodError | undefined)
| 25 | } |
| 26 | |
| 27 | function formatZodErrors(zodError: ZodError | undefined): string[] { |
| 28 | if (!zodError) return []; |
| 29 | |
| 30 | const errors: string[] = []; |
| 31 | |
| 32 | // Add form-level errors |
| 33 | if (zodError.formErrors && zodError.formErrors.length > 0) { |
| 34 | errors.push(...zodError.formErrors); |
| 35 | } |
| 36 | |
| 37 | // Add field-level errors |
| 38 | if (zodError.fieldErrors) { |
| 39 | Object.entries(zodError.fieldErrors).forEach(([field, fieldErrors]) => { |
| 40 | if (Array.isArray(fieldErrors) && fieldErrors.length > 0) { |
| 41 | fieldErrors.forEach((fieldError: string) => { |
| 42 | errors.push(`${field}: ${fieldError}`); |
| 43 | }); |
| 44 | } |
| 45 | }); |
| 46 | } |
| 47 | |
| 48 | return errors; |
| 49 | } |
| 50 | |
| 51 | function getErrorMessages(error: unknown): string[] { |
| 52 | let errorMessages: string[] = []; |
no test coverage detected