whycxzp
2021-11-01 0f85581e110e7f8443b534ff36c798bd93580a71
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package com.whyc.exception;
 
import com.whyc.dto.Response;
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.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;
 
/**
 * 针对RestController层捕捉异常,结果统一返回
 */
@RestControllerAdvice(annotations = RestController.class)
public class CustomExceptionResultHandler {
 
    @ExceptionHandler(Exception.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public Response sendErrorResponse2Defined(Exception e){
        return new Response().setII(0,e.toString());
    }
 
 
}