Skip to content

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

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

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

Conversation

@Moonwalker-rgb

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
@drips-wave

drips-wave Bot commented Jul 28, 2026

Copy link
Copy Markdown

@Moonwalker-rgb Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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