You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
compose-analysis/src/main/java/com/keyware/composeanalysis/config/GlobalExceptionHandler.java

33 lines
1012 B

package com.keyware.composeanalysis.config;
import com.keyware.common.base.response.Result;
import com.keyware.common.constant.enums.ResultCode;
import com.keyware.common.exception.BusinessException;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@Log4j2
@RestControllerAdvice
public class GlobalExceptionHandler {
//全局异常处理
@ExceptionHandler(value = Exception.class)
public Result defaultErrorHandler(Exception e) {
log.error("全局异常信息,ex={}",e.getMessage(),e);
return Result.fail(ResultCode.FAIL.getCode(), e.getMessage());
}
//自定义异常处理
//业务异常
@ExceptionHandler(value = BusinessException.class)
@ResponseBody
public Result businessExceptionHandler(BusinessException e) {
log.error("业务异常信息",e);
return Result.fail(e.getCode(), e.getMsg());
}
}