35 lines
1.3 KiB
Java
35 lines
1.3 KiB
Java
package io.icchain.wxcontractbot.config;
|
|
|
|
import io.icchain.wxcontractbot.utils.BaseResponse;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
/**
|
|
* 模块编号:io.icchain.wxcontractbot.config GlobalExceptionHandler
|
|
* 作 者:xuelei.wang
|
|
* 创建时间:2020/5/19 14:44
|
|
* 修改编号:1
|
|
* 描 述:DES
|
|
*/
|
|
@RestControllerAdvice
|
|
public class GlobalExceptionHandler {
|
|
|
|
private Logger logger= LoggerFactory.getLogger(GlobalExceptionHandler.class);
|
|
@ExceptionHandler(value = Exception.class)
|
|
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
public BaseResponse defaultErrorHandler(HttpServletRequest request, Exception exception) throws Exception {
|
|
BaseResponse baseResponse=new BaseResponse();
|
|
baseResponse.setSuccess(false);
|
|
baseResponse.setError_message("服务出现了异常,请联系开发人员!");
|
|
logger.error("全局拦截出现了异常:{},{}",request,exception);
|
|
return baseResponse;
|
|
}
|
|
}
|