Skip to content

✨ Expose validation error fields and add error mapping utilities - #172

Merged
flovouin merged 7 commits into
mainfrom
feat/validation-improvements
Aug 6, 2026
Merged

✨ Expose validation error fields and add error mapping utilities#172
flovouin merged 7 commits into
mainfrom
feat/validation-improvements

Conversation

@flovouin

@flovouin flovouin commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

📝 Description of the PR

Adds a fields property to the ValidationError, listing the path to each property that failed validation. Nested objects and arrays are referenced using their full path, e.g. child.id or items.0.name. The property is populated by the validateObject and parseObject utilities, and is empty when the validation failed for the payload as a whole.

Several utilities mapping business errors to their ErrorDto counterpart are also introduced, meant to be used with the tryMap utility and the @TryMap decorator: incorrectEntityVersionErrorAsDto, validationErrorAsDto, and forbiddenErrorAsDto. validationErrorAsDto formats the validation messages as a bullet list and returns the failing fields to the caller. It optionally accepts an error type, such that a subclass of the ValidationError can be matched instead of the base error.

The forbiddenErrorAsDto utility maps the new ForbiddenError, a business-level error meant to be thrown by authorization logic. Because such logic is usually, but not always, used in an HTTP context, the error itself is defined independently of NestJS. Its message is not returned to the caller, such that it can freely describe why the operation was denied.

📋 Check list

  • 🧪 Unit tests have been written.
  • 📝 Documentation has been updated.

@flovouin flovouin added the enhancement New feature or request label Aug 6, 2026
@flovouin
flovouin merged commit 83705c9 into main Aug 6, 2026
2 checks passed
@flovouin
flovouin deleted the feat/validation-improvements branch August 6, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant