我已经重构了代码,以使用spring webflux代替spring MVC,但是现在每当bean验证失败时,contoller建议中就会用WebExchangeBindException
代替HttpMessageNotReadableException
。
public Flux<UserContactsModel> getUserContacts(@RequestBody @Valid LoginModel loginDetail) {
return contactInfoService
.getUserContacts(loginDetailApiMapper.loginModelMonoToLoginBoMono(Mono.just(loginDetail)))
.flatMapIterable(
userContactsBO -> contactInfoMapper.userContactBoToModelList(userContactsBO));
}
控制器建议
@ExceptionHandler(value = {Exception.class})
protected ResponseEntity<Object> genericException(Exception ex) {
return new ResponseEntity<>(new Message(responseBody), HttpStatus.INTERNAL_SERVER_ERROR);
}
@ExceptionHandler(value = HttpMessageNotReadableException.class)
protected ResponseEntity<Object> handleHttpMessageNotReadable(
HttpMessageNotReadableException ex) {
return new ResponseEntity<>(new Message("Bad Request", reason), HttpStatus.BAD_REQUEST);
}