File was renamed from src/main/java/com/ycl/jxkg/configuration/spring/exception/ExceptionHandle.java |
| | |
| | | package com.ycl.jxkg.configuration.spring.exception; |
| | | package com.ycl.jxkg.config.spring.exception; |
| | | |
| | | import com.ycl.jxkg.base.RestResponse; |
| | | import com.ycl.jxkg.base.Result; |
| | | import com.ycl.jxkg.base.SystemCode; |
| | | import com.ycl.jxkg.utility.ErrorUtil; |
| | | import com.ycl.jxkg.utils.ErrorUtil; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.validation.BindException; |
| | |
| | | */ |
| | | @ExceptionHandler(Exception.class) |
| | | @ResponseBody |
| | | public RestResponse handler(Exception e) { |
| | | public Result handler(Exception e) { |
| | | logger.error(e.getMessage(), e); |
| | | return new RestResponse<>(SystemCode.InnerError.getCode(), SystemCode.InnerError.getMessage()); |
| | | return new Result<>(SystemCode.InnerError.getCode(), SystemCode.InnerError.getMessage()); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @ExceptionHandler(MethodArgumentNotValidException.class) |
| | | @ResponseBody |
| | | public RestResponse handler(MethodArgumentNotValidException e) { |
| | | public Result handler(MethodArgumentNotValidException e) { |
| | | String errorMsg = e.getBindingResult().getAllErrors().stream().map(file -> { |
| | | FieldError fieldError = (FieldError) file; |
| | | return ErrorUtil.parameterErrorFormat(fieldError.getField(), fieldError.getDefaultMessage()); |
| | | }).collect(Collectors.joining()); |
| | | return new RestResponse<>(SystemCode.ParameterValidError.getCode(), errorMsg); |
| | | return new Result<>(SystemCode.ParameterValidError.getCode(), errorMsg); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @ExceptionHandler(BindException.class) |
| | | @ResponseBody |
| | | public RestResponse handler(BindException e) { |
| | | public Result handler(BindException e) { |
| | | String errorMsg = e.getBindingResult().getAllErrors().stream().map(file -> { |
| | | FieldError fieldError = (FieldError) file; |
| | | return ErrorUtil.parameterErrorFormat(fieldError.getField(), fieldError.getDefaultMessage()); |
| | | }).collect(Collectors.joining()); |
| | | return new RestResponse<>(SystemCode.ParameterValidError.getCode(), errorMsg); |
| | | return new Result<>(SystemCode.ParameterValidError.getCode(), errorMsg); |
| | | } |
| | | |
| | | |