Shumilin Alexandr
01/17/2023, 10:32 AMdata class EmailVerificationStateRequestDto (
@field:NotBlank(message = "parameterName не указан")
@field:Size(min = 6, max = 6, message = "parameterName должен содержать 6 алфавитно-цифровых символов" )
@field:Pattern(regexp = "^[a-zA-Z0-9]+\$")
val parameterName: String?,
val email: String?
)
three validation for one field
and i have this class where i can get some information about error
p.s. service vy webFlux, Mono, Flux, Reactive
@ExceptionHandler(WebExchangeBindException::class)
fun handleException(bindException: WebExchangeBindException): ResponseEntity<String> {
val validationError = ValidationError(
bindException.fieldError?.defaultMessage
?: throw RuntimeException("Something wrong with validation error message")
)
return ResponseEntity.badRequest().body(objectMapper.writeValueAsString(validationError))
}
when i call controller method and set parameterName = “” i got 3 errors,
i want get 1 error NotBlank only, not all 3 validations, how can i do this?thanksforallthefish
01/17/2023, 1:09 PMShumilin Alexandr
01/17/2023, 1:56 PMnicholasnet
01/18/2023, 12:23 PM@ExceptionHandler(WebExchangeBindException::class)
suspend fun handleValidationError(exception: WebExchangeBindException): ResponseEntity<Response> {
if ((exception.reason == null) || (exception.reason != "Validation failure") || !exception.hasFieldErrors()) {
return getHttpResponseWithoutDetail(HttpStatus.BAD_REQUEST, exception.message)
}
if ((exception.reason == "Validation failure") && (exception.bindingResult.fieldErrors.isNotEmpty())) {
return ResponseEntity(
Response.withError(FormError.format(exception.bindingResult.fieldErrors)),
HttpStatus.UNPROCESSABLE_ENTITY
)
}
return getHttpResponseWithoutDetail(HttpStatus.UNPROCESSABLE_ENTITY, exception.message)
}
Shumilin Alexandr
01/18/2023, 12:25 PMnicholasnet
01/18/2023, 12:27 PMGroupSequence