Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved error messages for file validtors #14070

Open
1 task done
phlogisticfugu opened this issue Oct 17, 2024 · 2 comments
Open
1 task done

Improved error messages for file validtors #14070

phlogisticfugu opened this issue Oct 17, 2024 · 2 comments

Comments

@phlogisticfugu
Copy link

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

Not related to an explicit bug in Nest.js - this is an enhancement request

Describe the solution you'd like

Within the FileTypeValidator

buildErrorMessage(): string {
return `Validation failed (expected type is ${this.validationOptions.fileType})`;
}

to change the buildErrorMessage() method to:

  • take in the file: any input supported by the FileValidator
  • use that to also log the actual file?.type which was observed - to make troubleshooting easier

While we are at it, the MaxFileSizeValidator

buildErrorMessage(): string {
if ('message' in this.validationOptions) {
if (typeof this.validationOptions.message === 'function') {
return this.validationOptions.message(this.validationOptions.maxSize);
}
return this.validationOptions.message;
}

could also be modified to improve its error message to show the actual file size, in addition to the expected file size

Teachability, documentation, adoption, migration strategy

for the changelog:
Improved error messages for MaxSizeValidator and FileTypeValidator to include the observed actual size or filetype.

What is the motivation / use case for changing the behavior?

We are using the FileTypeValidator() within a @uploadedfile - and are getting errors in production where the user is uploading the wrong file type, and triggering this validator. However, the error message we see in our logs is: BadRequestException: Validation failed (expected type is .(png|jpeg|jpg|pdf)) - which does not describe the actual file type that the user actually used.

@phlogisticfugu phlogisticfugu added needs triage This issue has not been looked into type: enhancement 🐺 labels Oct 17, 2024
@VeerChaurasia
Copy link

hey @phlogisticfugu can I Take this one?

@kamilmysliwiec
Copy link
Member

PRs are more than welcome

@kamilmysliwiec kamilmysliwiec added scope: common effort1: hours priority: very low (5) Very low-priority issue for consideration and removed needs triage This issue has not been looked into labels Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants