package com.moral.api.exception;
|
|
import com.moral.constant.Constants;
|
import com.moral.constant.ResultMessage;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.http.HttpStatus;
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
|
|
@ControllerAdvice
|
@ResponseBody
|
public class GlobalExceptionHandler {
|
/**
|
* 处理全部异常
|
*/
|
@ExceptionHandler
|
@ResponseBody
|
@ResponseStatus(HttpStatus.OK)
|
public ResultMessage handleException(Exception ex) {
|
ex.printStackTrace();
|
return ResultMessage.fail(Constants.CODE_OPERATION_FAILED, "请求失败");
|
}
|
|
/**
|
* 处理BusinessException异常
|
*/
|
@ExceptionHandler({BusinessException.class})
|
@ResponseBody
|
@ResponseStatus(HttpStatus.OK)
|
public ResultMessage handleUserNotExistException(BusinessException ex) {
|
return ResultMessage.fail(Constants.CODE_OPERATION_FAILED, "请求用户数据失败");
|
}
|
|
}
|