feat: 全局异常捕获BizException异常

main
itao 11 months ago
parent a503fd09fc
commit eedf241f45

@ -1,22 +1,30 @@
package com.luoo.tag.controller; package com.luoo.tag.controller;
import com.luoo.common.exception.BizException;
import entity.Result; import entity.Result;
import entity.StatusCode; import entity.StatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/** /**
* *
*/ */
@Slf4j
@ControllerAdvice @ControllerAdvice
public class BaseExceptionHandler { public class BaseExceptionHandler {
@ExceptionHandler(value = Exception.class) @ExceptionHandler(value = Exception.class)
@ResponseBody @ResponseBody
public Result error(Exception e){ public Result error(Exception e){
e.printStackTrace(); log.error("执行出错", e);
return new Result(false, StatusCode.ERROR, "执行出错"); return new Result(false, StatusCode.ERROR, "执行出错");
} }
@ExceptionHandler(value = BizException.class)
@ResponseBody
public Result error(BizException e){
log.info("业务错误", e);
return new Result(false, StatusCode.ERROR, "业务错误");
}
} }

Loading…
Cancel
Save