node.js - NestJs - Class-validator لا يُرجع كائن خطأ التحقق الكامل


أنا أستخدم class-validator في NestJS لإنشاء التحققات مثل هذا:

export class LoginDTO {
@IsEmail()
@MinLength(4)
email: string;

@IsNotEmpty()
@MinLength(4)
password: string;

}

يعمل، لكن ليس كما هو متوقع. الكائن المُرجع يبدو هكذا:

{
"statusCode": 400,
"message": [
    "email must be longer than or equal to 4 characters",
    "email must be an email"
],
"error": "Bad Request"

}

بينما أريد أن يحتوي على كل المعلومات مثل هذا:

{
    "statusCode": 400,
    [{
        target: /* post object */,
        property: "title",
        value: "Hello",
        constraints: {
        length: "$property must be longer than or equal to 10 characters"
    }]
    "error": "Bad Request"
}

كيف تفعل لاسترجاع كل الخصائص المفقودة؟

الإجابة رقم 1

كان هذا تغييرًا جذريًا في Nestv7. من دليل الترحيل عند استخدام ValidationPipe يمكنك تمرير خاصية exceptionFactory على هذا النحو

exceptionFactory: (errors) => new BadRequestException(errors),

ويجب أن يعطيك ما تريد.