Skip to content

Conversation

@ThisIsMissEm
Copy link

@ThisIsMissEm ThisIsMissEm commented Jan 21, 2026

πŸ”— Linked issue

I didn't create an issue first, but this was a feature added in Vine.js back in June 2024.

❓ Type of change

  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Sometimes when validating requests, you just want to attempt to validate the request, but then handle the errors yourself, instead of having them propagate upwards out of your controller.

This adds support for validator.tryValidate from Vine.js to the HttpRequest as tryValidateUsing.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

This will require a documentation change, if we agree this is a good feature to have.

Comment on lines -110 to +151
const data = validatorOptions.data || {
...requestBody,
params: this.#ctx.request.params(),
headers: this.#ctx.request.headers(),
cookies: this.#ctx.request.cookiesList(),
}
const data = validatorOptions.data || this.requestData()
Copy link
Author

Choose a reason for hiding this comment

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

@thetutlage I was a little unsure about what this was actually used for here? It feels like validatorOptions.data should be merged with the requestBody, params, headers, cookies, etc? But the original code was replacing the request data with the validator options data.

I'm not sure why you'd do request.validateUsing(myValidator, { data: { foo: 'bar' } }) where the request isn't even factored into the validation? Wouldn't you just do myValidator.validate({ foo: 'bar' }) for that? Or is this to have the error reporter and messages provider setup still when not actually validating a request?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, the data property is used to specify your own custom data without performing any merging under the hood.

The request validator can still be helpful, because (as you mentioned) it allows for using correct messages provider and the error reporter. Also, sometimes its more about uniformity as well

Copy link
Author

Choose a reason for hiding this comment

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

Okay, cool, just wanted to verify this behavior was definitely the expected behavior here

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.

2 participants