Skip to content
Discussion options

You must be logged in to vote

@onozaty use the stopAtFirstError option when calling validate(). this stops validation on each property after the first constraint fails, so if @IsNotEmpty already caught the empty string, @IsEmail won't run:

const errors = await validate(dto, { stopAtFirstError: true });

in NestJS, pass it to ValidationPipe:

app.useGlobalPipes(new ValidationPipe({ stopAtFirstError: true }));

this is a built-in option in class-validator v0.14+. make sure your decorators are ordered the way you want (first decorator = first check).

ref: class-validator validate options

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@onozaty
Comment options

Answer selected by onozaty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants