@ControllerAdvice
public class GlobalException {
@ExceptionHandler(HolidayException.class)
@ResponseBody
public ApiReturn holidayExceptionHandler(HolidayException holidayException){
return ApiReturn.error(holidayException.getCode(),holidayException.getMsg());
}
@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseBody
public ApiReturn handleExplanation(MethodArgumentNotValidException e){
return handleBinding(e.getBindingResult());
}
private ApiReturn handleBinding(BindingResult result){
List list1=new ArrayList<>();
if(result.hasErrors()){
List<ObjectError> allErrors=result.getAllErrors();
for(ObjectError objectError:allErrors){
String message=objectError.getDefaultMessage();
list1.add(message);
}
}
if(list1.size()==0){
return ApiReturn.error(ExceptionEnum.PARAM_NULL);
}
return ApiReturn.error(ExceptionEnum.PARAM_NULL.getCode(),list1.toString());
}
}