Improved error messages for file validtors #14070
Labels
effort1: hours
priority: very low (5)
Very low-priority issue for consideration
scope: common
type: enhancement 🐺
Is there an existing issue that is already proposing this?
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
to change the
buildErrorMessage()
method to:file: any
input supported by theFileValidator
file?.type
which was observed - to make troubleshooting easierWhile we are at it, the MaxFileSizeValidator
nest/packages/common/pipes/file/max-file-size.validator.ts
Lines 20 to 27 in 198eaf7
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.The text was updated successfully, but these errors were encountered: