Skip to content

Commit 2b4a2d8

Browse files
committed
fix: 🐛 异常捕获错误码判断修复
1 parent f846094 commit 2b4a2d8

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

bubble-spring-boot-starters/bubble-spring-boot-starter-web/src/main/java/cn/fxbin/bubble/web/handler/DefaultGlobalExceptionHandler.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package cn.fxbin.bubble.web.handler;
22

3+
import cn.fxbin.bubble.core.dataobject.ErrorCode;
34
import cn.fxbin.bubble.core.dataobject.GlobalErrorCode;
4-
import cn.fxbin.bubble.core.exception.ServiceException;
55
import cn.fxbin.bubble.core.dataobject.Result;
6-
import cn.fxbin.bubble.core.dataobject.ErrorCode;
6+
import cn.fxbin.bubble.core.exception.ServiceException;
77
import com.fasterxml.jackson.core.JsonParseException;
88
import com.fasterxml.jackson.databind.JsonMappingException;
9+
import jakarta.validation.ConstraintViolation;
10+
import jakarta.validation.ConstraintViolationException;
911
import lombok.extern.slf4j.Slf4j;
1012
import org.springframework.http.HttpStatus;
1113
import org.springframework.util.ObjectUtils;
@@ -18,10 +20,8 @@
1820
import org.springframework.web.bind.annotation.RestControllerAdvice;
1921
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
2022

21-
import jakarta.validation.ConstraintViolation;
22-
import jakarta.validation.ConstraintViolationException;
2323
import java.util.List;
24-
import java.util.stream.Collectors;
24+
import java.util.Objects;
2525

2626
/**
2727
* DefaultGlobalExceptionHandler
@@ -43,7 +43,7 @@ public Result<String> exceptionHandler(Exception exception) {
4343
@ExceptionHandler(value = ServiceException.class)
4444
public Result<String> exceptionHandler(ServiceException ex) {
4545
log.warn("[ServiceException]", ex);
46-
return Result.failure((ErrorCode.valueOf(ex.getErrcode()).isError() ? GlobalErrorCode.INTERNAL_SERVER_ERROR.value() : ex.getErrcode()), ex.getMessage());
46+
return Result.failure(Objects.requireNonNull(ErrorCode.valueOf(ex.getErrcode())).isError() ? ex.getErrcode() : GlobalErrorCode.INTERNAL_SERVER_ERROR.value(), ex.getMessage());
4747
}
4848

4949
/**

0 commit comments

Comments
 (0)