Skip to content

[Refactor] Zod validation errors are returned as semicolon-joined strings — not machine-parseable #771

Description

@RUKAYAT-CODER

Overview

src/lib/validation.ts formats Zod errors by joining all issue messages with '; ' into a single string. Client-side code cannot programmatically distinguish which field failed or display field-specific inline errors. Every frontend form must parse a freeform string to show proper per-field validation feedback.

Specifications

Features:

  • Validation error responses include a structured array of { field, message } objects
  • Clients can map errors to specific form fields without string parsing

Tasks:

  • Change validateBody() error response to: { errors: zodResult.error.issues.map(i => ({ field: i.path.join('.'), message: i.message })) }
  • Update the HTTP error response body to { message: 'Validation failed', errors: [...] }
  • Update all frontend form error handlers to consume the structured format
  • Update API tests that assert on the error string format

Impacted Files:

  • src/lib/validation.ts
  • All API route files using validateBody()
  • Frontend form components handling API validation errors

Acceptance Criteria

  • Error responses include a structured errors array with field and message per issue
  • Frontend forms display per-field error messages from the API response
  • No semicolon-joined error string format remains

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions