-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
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
nest/packages/common/pipes/file/file-type.validator.ts
Lines 23 to 25 in 198eaf7
| buildErrorMessage(): string { | |
| return `Validation failed (expected type is ${this.validationOptions.fileType})`; | |
| } |
to change the buildErrorMessage() method to:
- take in the
file: anyinput supported by theFileValidator - use that to also log the actual
file?.typewhich was observed - to make troubleshooting easier
While we are at it, the MaxFileSizeValidator
nest/packages/common/pipes/file/max-file-size.validator.ts
Lines 20 to 27 in 198eaf7
| 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.