package com.whyc.exception;
|
|
import com.whyc.dto.Response;
|
import org.springframework.http.HttpStatus;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
/**
|
* 针对RestController层捕捉异常,结果统一返回
|
*/
|
@RestControllerAdvice(annotations = {RestController.class, Controller.class})
|
public class CustomExceptionResultHandler {
|
|
/**错误捕捉,状态码:202*/
|
@ExceptionHandler(Exception.class)
|
@ResponseStatus(HttpStatus.ACCEPTED)
|
public Response sendErrorResponse2Defined(Exception e, HttpServletResponse response){
|
return new Response().setII(0,"接口请求异常,请联系软件人员进行处理.异常信息"+e.toString());
|
}
|
|
|
}
|