io.github.wslxm.springbootplus2.config.GlobalExceptionHandler Maven / Gradle / Ivy
The newest version!
package io.github.wslxm.springbootplus2.config;
import io.github.wslxm.springbootplus2.core.config.error.ErrorException;
import io.github.wslxm.springbootplus2.core.result.Result;
import io.github.wslxm.springbootplus2.core.result.ResultType;
import io.github.wslxm.springbootplus2.core.utils.I18nUtil;
import io.github.wslxm.springbootplus2.core.utils.error.XjErrorMsgUtil;
import io.github.wslxm.springbootplus2.starter.redis.config.error.RedisErrorException;
import io.github.wslxm.springbootplus2.starter.robot.service.RobotService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.MethodParameter;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.validation.BindException;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 异常处理类/ 全局异常 /自定义异常
*/
@SuppressWarnings("all")
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
@Autowired
private HttpServletRequest request;
@Autowired
private HttpServletResponse response;
@Autowired
private RobotService robotService;
/**
* 全局异常|受检查异常 --> Exception 。可以理解为错误,必须要开发者解决以后才能编译通过,这里JSR 303 为受检查异常
* 全局异常|运行时异常 --> RuntimeException extends Exception: 运行时异常,又称不受检查异常,不受检查!
* 受检查异常解决的方法有两种1:throw到上层,2,try-catch处理。
*
* @param e
* @return io.github.wslxm.admincore.platform.vo.ResponseData
* @author ws
* @mail [email protected]
* @date 2020/2/9 0009 10:06
*/
@ExceptionHandler(Exception.class)
public Result