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;
|
|
/**
|
* 针对RestController层捕捉异常,结果统一返回
|
*/
|
@RestControllerAdvice(annotations = {RestController.class, Controller.class})
|
public class CustomExceptionResultHandler {
|
|
@ExceptionHandler(Exception.class)
|
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
public Response sendErrorResponse2Defined(Exception e){
|
return new Response().setII(0,e.toString());
|
}
|
|
|
}
|