Skip to content

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

Merged
nanaf6203-bit merged 1 commit into
MettaChain:mainfrom
gbengaeben:fix/967-validation-error-format
Jul 29, 2026
Merged

fix: standardize API validation error format with error codes (#967)#1011
nanaf6203-bit merged 1 commit into
MettaChain:mainfrom
gbengaeben:fix/967-validation-error-format

Conversation

@gbengaeben

Copy link
Copy Markdown
Contributor

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

@nanaf6203-bit nanaf6203-bit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nanaf6203-bit
nanaf6203-bit merged commit f09f541 into MettaChain:main Jul 29, 2026
14 checks passed
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

2 participants