Spring boot не хочет выводить мои ошибки валидации в Noty
Добавляется equipments, в логах всё отлично, выводится, что в полях ошибки:
2023-01-17 09:50:17.882 WARN 12684 --- [nio-8081-exec-4] r.i.util.exception.ExceptionInfoHandler : VALIDATION_ERROR at request http://localhost:8081/profile/equipments/: org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 5 errors
Field error in object 'equipment' on field 'description': rejected value []; codes [NotBlank.equipment.description,NotBlank.description,NotBlank.java.lang.String,NotBlank]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [equipment.description,description]; arguments []; default message [description]]; default message [не должно быть пустым]
Field error in object 'equipment' on field 'company': rejected value []; codes [Size.equipment.company,Size.company,Size.java.lang.String,Size]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [equipment.company,company]; arguments []; default message [company],70,2]; default message [размер должен находиться в диапазоне от 2 до 70]
Field error in object 'equipment' on field 'name': rejected value []; codes [NotBlank.equipment.name,NotBlank.name,NotBlank.java.lang.String,NotBlank]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [equipment.name,name]; arguments []; default message [name]]; default message [не должно быть пустым]
Field error in object 'equipment' on field 'description': rejected value []; codes [Size.equipment.description,Size.description,Size.java.lang.String,Size]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [equipment.description,description]; arguments []; default message [description],120,2]; default message [размер должен находиться в диапазоне от 2 до 120]
Field error in object 'equipment' on field 'name': rejected value []; codes [Size.equipment.name,Size.name,Size.java.lang.String,Size]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [equipment.name,name]; arguments []; default message [name],128,2]; default message [размер должен находиться в диапазоне от 2 до 128]
Но у меня есть js, в котором это должно выводиться:
$(document).ajaxError(function (event, jqXHR, options, jsExc) {
alert(event);
alert(options);
failNoty(jqXHR,options);
});
function failNoty(jqXHR,options) {
closeNoty();
var errorInfo = jqXHR.responseJSON;
failedNote = new Noty({
text: ""+errorInfo.typeMessage+"",
type: "error",
layout: "bottomRight"
});
failedNote.show();
}
Вместо ошибок выдаётся undefined.
EquipmentUIController:
@RestController
@Slf4j
@RequestMapping(value = EquipmentUIController.URL, produces = MediaType.APPLICATION_JSON_VALUE)
public class EquipmentUIController extends AbstractEquipmentController{
static final String URL = "/profile/equipments";
@GetMapping("")
public List<EquipmentTo> getAll() {
log.info("EquipmentUIController getAll");
return super.getAll() ;
}
@PostMapping
@ResponseStatus(HttpStatus.NO_CONTENT)
public void createOrUpdate(@Validated(View.Web.class) Equipment equipment) {
log.info("EquipmentUIController createOrUpdate");
if (equipment.isNew()) {
super.create(equipment);
} else {
super.update(equipment);
}
}
@Override
@GetMapping("/{id}")
public Equipment get(@PathVariable int id) {
log.info("EquipmentUIController get id");
return super.get(id);
}
@Override
@DeleteMapping("/{id}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void delete(@PathVariable int id) {
super.delete(id);
}
}
Не знаю какие участки кода вывести сюда, сам проект не маленький, вот git: https://github.com/Dvorneg/it
Источник: Stack Overflow на русском