When using the decorator @ValidateNested({each: true]) from class-validator like in the above example, the I18nService.validate(...) method will throw the following error TypeError: Cannot convert undefined or null to object.
This is because in the absence of validation errors in the parent, the constraints property of the ValidationError will be undefined. Thus, the call to Object.keys(error.constraints) in the formatI18nErrors util function will fail. Since Object.keys only works with objects.
coverage: 90.837% (-0.07%) from 90.909%
when pulling 7ad950d9974d81046f66984ed03cc9ccdf2d007e on velvet-lynx:fix/validate-nested-each
into c7946131c9ea84468f676f7b6c5239387e406d35 on toonvanstrijp:main.
Description
When using the decorator
@ValidateNested({each: true])
fromclass-validator
like in the above example, theI18nService.validate(...)
method will throw the following errorTypeError: Cannot convert undefined or null to object
.This is because in the absence of validation errors in the parent, the
constraints
property of theValidationError
will beundefined
. Thus, the call toObject.keys(error.constraints)
in theformatI18nErrors
util function will fail. SinceObject.keys
only works with objects.Linked Issues
Fixes #633
Additional context