package com.zy.bms.common.controller; import com.zy.bms.common.ServerResponse; import com.zy.bms.common.exception.ApiRuntimeException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; /** * 全局异常拦截 * * @author chenyi * Create on 2019/10/21 */ @RestControllerAdvice public class ExceptionController { /** * 对参数类型不匹配异常做统一拦截处理 */ @ExceptionHandler(value = MethodArgumentTypeMismatchException.class) public ServerResponse MethodArgumentTypeMismatchExceptionHandler() { return ServerResponse.createByErrorMsg("参数类型错误"); } /** * 对运行时异常拦截 */ @ExceptionHandler(value = ApiRuntimeException.class) public ServerResponse ApiRuntimeExceptionHandler(ApiRuntimeException apiRuntimeException) { return ServerResponse.createByErrorMsg(apiRuntimeException.getMsg()); } }