mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
全局异常处理器
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package cn.lihongjie.coal.config;
|
||||
|
||||
import cn.lihongjie.coal.dto.R;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
@RestControllerAdvice
|
||||
@Slf4j
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
|
||||
@ExceptionHandler(BizException.class)
|
||||
public R handleException(BizException ex, HttpServletRequest request) {
|
||||
logException(ex, request);
|
||||
return R.fail("bizError", ex.getMessage());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ExceptionHandler(RuntimeException.class)
|
||||
public R handleException(RuntimeException ex, HttpServletRequest request) {
|
||||
logException(ex, request);
|
||||
return R.fail("sysError", ex.getMessage());
|
||||
}
|
||||
@ExceptionHandler(Exception.class)
|
||||
public R handleException(Exception ex, HttpServletRequest request) {
|
||||
logException(ex, request);
|
||||
return R.fail("sysError", ex.getMessage());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void logException(Exception ex, HttpServletRequest request) {
|
||||
log.info("接口调用异常: {}\nURL:{} {}", ex.getMessage(), request.getMethod(), request.getRequestURL(), ex);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
@@ -12,7 +13,7 @@ public class CoalBlendRequest {
|
||||
|
||||
|
||||
private List<CoalConstraint> constraints;
|
||||
|
||||
@JsonIgnore
|
||||
private Map<String, CoalConstraint> constraintMap;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
@@ -26,6 +27,7 @@ public class CoalInfo {
|
||||
private List<CoalParameter> parameters;
|
||||
|
||||
|
||||
@JsonIgnore
|
||||
private Map<String, CoalParameter> parameterMap;
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.lihongjie.coal.exception;
|
||||
|
||||
|
||||
import lombok.experimental.StandardException;
|
||||
|
||||
@StandardException
|
||||
public class BizException extends RuntimeException{
|
||||
}
|
||||
Reference in New Issue
Block a user