package com.zy.omp.common.controller; import com.zy.omp.common.ServerResponse; import com.zy.omp.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.createByError(); } /** * 对运行时异常拦截 */ @ExceptionHandler(value = ApiRuntimeException.class) public ServerResponse ApiRuntimeExceptionHandler() { return ServerResponse.createByError(); } }