Skip to content

fix: standardize API validation error format with error codes (#967) - #1011

Open
gbengaeben wants to merge 1 commit into
MettaChain:mainfrom
gbengaeben:fix/967-validation-error-format
Open

fix: standardize API validation error format with error codes (#967)#1011
gbengaeben wants to merge 1 commit into
MettaChain:mainfrom
gbengaeben:fix/967-validation-error-format

Conversation

@gbengaeben

Copy link
Copy Markdown

Summary

Adds a ValidationExceptionFilter that catches BadRequestException errors from ValidationPipe and outputs a standardized JSON format with error codes.

Changes

  • New file: src/common/filters/validation-exception.filter.ts

    • Catches BadRequestException with array messages (validation errors)
    • Outputs: { success, statusCode, errors: [{ field, message, code, constraints }] }
    • Auto-infers error codes from class-validator messages (IS_EMAIL, MIN_LENGTH, IS_NOT_EMPTY, etc.)
    • i18n-aware via I18nService for language resolution
    • Falls back to standard format for non-validation BadRequestException
  • Modified: src/app.module.ts

    • Registers ValidationExceptionFilter as a global APP_FILTER

Acceptance Criteria

  • Consistent error format: { field, message, code, constraints }
  • Field names follow API convention (camelCase)
  • Error codes for each validation type
  • Documentation of error format

Closes #967

…hain#967)

- Add ValidationExceptionFilter that catches BadRequestException
- Output standardized JSON: { success, statusCode, errors: [{ field, message, code, constraints }] }
- Field names follow camelCase convention (class-validator defaults)
- Auto-infer error codes (IS_EMAIL, MIN_LENGTH, IS_NOT_EMPTY, etc.)
- i18n-aware with language resolution from Accept-Language / user preference
- Register globally via APP_FILTER in AppModule

Closes MettaChain#967
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Standardize API validation error format across all endpoints

1 participant