whycxzp
2021-11-12 b1bd61cdf428e5050a78092a11def6e77fb46c81
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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 {
 
    @ExceptionHandler(Exception.class)
    @ResponseStatus(HttpStatus.ACCEPTED)
    public Response sendErrorResponse2Defined(Exception e, HttpServletResponse response){
        return new Response().setII(0,"接口请求异常,请联系软件人员进行处理.异常信息"+e.toString());
    }
 
 
}