Skip to content

Commit

Permalink
升级opensabre版本为0.0.9,升级springboot为2.7.18,修改部分统一异常处理http状态码
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoutaoo committed Feb 7, 2024
1 parent 1ecd8b6 commit e0c4126
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 15 deletions.
18 changes: 9 additions & 9 deletions opensabre-base-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
<spring-boot-maven-plugin.version>2.7.5</spring-boot-maven-plugin.version>
<dockerfile-maven-plugin.version>1.4.13</dockerfile-maven-plugin.version>
<!-- 依赖 -->
<spring.boot.version>2.7.5</spring.boot.version>
<spring.cloud.version>2021.0.4</spring.cloud.version>
<spring.cloud.alibaba.version>2021.0.4.0</spring.cloud.alibaba.version>
<spring-boot-starter-data-redis.version>2.7.5</spring-boot-starter-data-redis.version>
<spring.boot.version>2.7.18</spring.boot.version>
<spring.cloud.version>2021.0.9</spring.cloud.version>
<spring.cloud.alibaba.version>2021.0.5.0</spring.cloud.alibaba.version>
<spring-boot-starter-data-redis.version>2.7.18</spring-boot-starter-data-redis.version>
<jetcache-starter-redis.version>2.7.5</jetcache-starter-redis.version>
<springdoc-openapi-ui.version>1.6.12</springdoc-openapi-ui.version>
<swagger-annotations.version>2.2.4</swagger-annotations.version>
Expand All @@ -38,16 +38,16 @@
<commons-pool2.version>2.11.1</commons-pool2.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
<hutool.version>5.8.18</hutool.version>
<spring-webmvc.version>5.3.23</spring-webmvc.version>
<spring-webmvc.version>5.3.31</spring-webmvc.version>
<feign-interceptors>1.1.2</feign-interceptors>
<guava.version>31.1-jre</guava.version>
<jackson-databind.version>2.13.4.2</jackson-databind.version>
<jackson-annotations.version>2.13.4</jackson-annotations.version>
<jackson-databind.version>2.13.5</jackson-databind.version>
<jackson-annotations.version>2.13.5</jackson-annotations.version>
<jasypt-springboot.version>3.0.5</jasypt-springboot.version>
<!-- 测试 -->
<junit-jupiter.version>5.9.1</junit-jupiter.version>
<spring-test.version>5.3.23</spring-test.version>
<spring-boot-starter-test.version>2.7.5</spring-boot-starter-test.version>
<spring-test.version>5.3.31</spring-test.version>
<spring-boot-starter-test.version>2.7.18</spring-boot-starter-test.version>
<httpclient5.version>5.2.1</httpclient5.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://localhost:8000/oaut
server.shutdown=graceful
#==============敏感信息加密配置===============#
jasypt.encryptor.password=${JASYPT_ENCRYPTOR_PASSWORD:Pa55w0rd@opensabre}
#==============管理端点===============#
#启用配置里的info开头的变量
management.info.env.enabled=true
info.name=${spring.application.name}
info.version=${application.formatted-version}
info.java.version=${java.version}
info.opensabre.version=${opensabre.version}
info.opensabre.cloud.az=${opensabre.cloud.az}
info.opensabre.cloud.region=${opensabre.cloud.region}
#==============脱敏===============#
opensabre.sensitive.log.enabled=false
opensabre.sensitive.log.rules=mobile,idCard,phone
Expand Down
4 changes: 4 additions & 0 deletions opensabre-starter-persistence/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.github.opensabre</groupId>
<artifactId>opensabre-starter-boot</artifactId>
</dependency>
<!--使用 lombok 简化 Java 代码-->
<dependency>
<groupId>org.projectlombok</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import io.github.opensabre.common.core.exception.SystemErrorType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
Expand All @@ -22,18 +24,21 @@
public class SentinelExceptionHandlerAdvice {

@ExceptionHandler(BlockException.class)
@ResponseStatus(HttpStatus.TOO_MANY_REQUESTS)
public Result blockException(BlockException e) {
log.error("block exception:{}", e.getRule());
return Result.fail(SystemErrorType.SYSTEM_BUSY);
}

@ExceptionHandler(FlowException.class)
@ResponseStatus(HttpStatus.TOO_MANY_REQUESTS)
public Result flowException(FlowException e) {
log.error("flow exception:{}", e.getRule());
return Result.fail(SystemErrorType.SYSTEM_BUSY);
}

@ExceptionHandler(DegradeException.class)
@ResponseStatus(HttpStatus.TOO_MANY_REQUESTS)
public Result degradeException(DegradeException e) {
log.error("degrade exception:{}", e.getRule());
return Result.fail(SystemErrorType.SYSTEM_BUSY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.HttpMediaTypeNotSupportedException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.MissingServletRequestParameterException;
Expand All @@ -25,31 +26,39 @@ public class DefaultGlobalExceptionHandlerAdvice {

@ExceptionHandler(value = {MissingServletRequestParameterException.class})
public Result missingServletRequestParameterException(MissingServletRequestParameterException ex) {
log.error("missing servlet request parameter exception:{}", ex.getMessage());
log.warn("missing servlet request parameter exception:{}", ex.getMessage());
return Result.fail(SystemErrorType.ARGUMENT_NOT_VALID);
}

@ExceptionHandler(value = {MethodArgumentNotValidException.class})
public Result argumentInvalidException(MethodArgumentNotValidException ex) {
log.error("service exception:{}", ex.getMessage());
log.warn("service exception:{}", ex.getMessage());
return Result.fail(SystemErrorType.ARGUMENT_NOT_VALID, ex.getBindingResult().getFieldError().getDefaultMessage());
}

@ExceptionHandler(value = {HttpMessageNotReadableException.class})
public Result httpMessageConvertException(HttpMessageNotReadableException ex) {
log.error("http message convert exception:{}", ex.getMessage());
log.warn("http message convert exception:{}", ex.getMessage());
return Result.fail(SystemErrorType.ARGUMENT_NOT_VALID, "数据解析错误:" + ex.getMessage());
}

@ExceptionHandler(value = {MultipartException.class})
public Result uploadFileLimitException(MultipartException ex) {
log.error("upload file size limit:{}", ex.getMessage());
log.warn("upload file size limit:{}", ex.getMessage());
return Result.fail(SystemErrorType.UPLOAD_FILE_SIZE_LIMIT);
}

@ExceptionHandler(value = {HttpRequestMethodNotSupportedException.class})
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
public Result notSupportedMethodException(HttpRequestMethodNotSupportedException ex) {
log.error("http request method not supported exception {}", ex.getMessage());
log.warn("http request method not supported exception {}", ex.getMessage());
return Result.fail(SystemErrorType.METHOD_NOT_SUPPORTED);
}

@ExceptionHandler(value = {HttpMediaTypeNotSupportedException.class})
@ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
public Result notSupportedMethodException(HttpMediaTypeNotSupportedException ex) {
log.warn("http request method not supported exception {}", ex.getMessage());
return Result.fail(SystemErrorType.METHOD_NOT_SUPPORTED);
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<nexus-staging-maven-plugin.version>1.6.8</nexus-staging-maven-plugin.version>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>

<revision>0.0.8</revision>
<revision>0.0.9</revision>
</properties>

<!--发布仓库的定义-->
Expand Down

0 comments on commit e0c4126

Please sign in to comment.