package com.dsh.app.advice;
|
|
import cn.mb.cloud.common.core.constant.enums.ErrorCodeConstants;
|
import cn.mb.cloud.common.core.exception.BusinessException;
|
import cn.mb.cloud.common.core.util.ResponseData;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.http.HttpStatus;
|
import org.springframework.web.bind.annotation.*;
|
|
@Slf4j
|
@RestControllerAdvice
|
public class ControllerException {
|
|
@ExceptionHandler(BusinessException.class)
|
@ResponseStatus(HttpStatus.OK)
|
@ResponseBody
|
public ResponseData bussiness(BusinessException e) {
|
log.error("业务异常 message= " + e.getMessage() + " code= " + e.getErrorCode(), e);
|
return ResponseData.builder().code(ErrorCodeConstants.FAIL.getValue()).
|
msg(e.getMessage()).build();
|
}
|
|
@ExceptionHandler(RuntimeException.class)
|
@ResponseStatus(HttpStatus.OK)
|
@ResponseBody
|
public ResponseData runtimeException(RuntimeException e) {
|
log.error("运行时异常信息" + e.getMessage(), e);
|
return ResponseData.builder().code(ErrorCodeConstants.FAIL.getValue()).msg(e.getMessage()).build();
|
}
|
|
/**
|
* 全局异常.
|
*
|
* @param e the e
|
* @return R
|
*/
|
|
@ExceptionHandler(Exception.class)
|
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
@ResponseBody
|
public ResponseData exception(Exception e) {
|
log.error("全局异常信息" + e.getMessage(), e);
|
return ResponseData.fail();
|
}
|
}
|