Skip to content

Commit

Permalink
📝 v2.5.4.55
Browse files Browse the repository at this point in the history
1. 整合代码,将constant包代码整合至common包中。删除constant包。
2. 完善Rest接口校验机制,以及相关自定义错误码
3. 统一spring boot validation错误信息,将其整合至平台统一响应实体Result中。无须在各个Rest接口中,添加BindingResult参数。
  • Loading branch information
herodotus-ecosystem committed Aug 18, 2021
1 parent 2c6d73f commit fd9096b
Show file tree
Hide file tree
Showing 97 changed files with 440 additions and 616 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<a href="https://nacos.io/zh-cn/index.html" target="_blank"><img src="https://img.shields.io/badge/Nacos-2.0.3-brightgreen" alt="Nacos 2.0.3"></a>
<a href="./LICENSE"><img src="https://img.shields.io/badge/License-Apache--2.0-blue" alt="License Apache 2.0"></a>
<a href="https://blog.csdn.net/Pointer_v" target="_blank"><img src="https://img.shields.io/badge/Author-%E7%A0%81%E5%8C%A0%E5%90%9B-orange" alt="码匠君"></a>
<a href="#" target="_blank"><img src="https://img.shields.io/badge/Version-2.5.4.50-red" alt="Version 2.5.4.50"></a>
<a href="#" target="_blank"><img src="https://img.shields.io/badge/Version-2.5.4.55-red" alt="Version 2.5.4.55"></a>
<a href="https://gitee.com/herodotus/eurynome-cloud"><img src="https://gitee.com/herodotus/eurynome-cloud/badge/star.svg?theme=dark" alt="Gitee star"></a>
<a href="https://gitee.com/herodotus/eurynome-cloud"><img src="https://gitee.com/herodotus/eurynome-cloud/badge/fork.svg?theme=dark" alt="Gitee fork"></a>
</p>
Expand Down
2 changes: 1 addition & 1 deletion configurations/docker/docker-compose/herodotus/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=2.5.4.50
VERSION=2.5.4.55
GATEWAY_SERVICE_NAME=eurynome-cloud-gateway
GATEWAY_SERVICE_PORT=8847
UAA_SERVICE_NAME=eurynome-cloud-uaa
Expand Down
7 changes: 1 addition & 6 deletions dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<groupId>cn.herodotus.eurynome</groupId>
<artifactId>dependencies</artifactId>
<version>2.5.4.50</version>
<version>2.5.4.55</version>
<packaging>pom</packaging>

<name>eurynome-cloud-dependencies</name>
Expand Down Expand Up @@ -124,11 +124,6 @@
<version>${spring-boot-admin.version}</version>
</dependency>
<!-- Eurynome Cloud -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>eurynome-cloud-constant</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>eurynome-cloud-common</artifactId>
Expand Down
8 changes: 2 additions & 6 deletions packages/eurynome-cloud-assistant/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<parent>
<artifactId>packages</artifactId>
<groupId>cn.herodotus.eurynome</groupId>
<version>2.5.4.50</version>
<version>2.5.4.55</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -47,17 +47,13 @@

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-kafka</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-kafka</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

package cn.herodotus.eurynome.assistant.annotation;

import cn.herodotus.eurynome.constant.magic.PropertyConstants;
import cn.herodotus.eurynome.common.constant.magic.PropertyConstants;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;

import java.lang.annotation.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
* Date: 2021/05/07 11:28:07
*/

package cn.herodotus.eurynome.common.exception;
package cn.herodotus.eurynome.assistant.exception;

import cn.herodotus.eurynome.common.constant.enums.ResultStatus;
import cn.herodotus.eurynome.common.domain.Result;
import cn.herodotus.eurynome.constant.enums.ResultStatus;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -36,8 +37,9 @@
*
* @author gengwei.zheng
*/
@Slf4j
public class GlobalExceptionHandler {
public class HerodotusExceptionHandler {

private static final Logger log = LoggerFactory.getLogger(HerodotusExceptionHandler.class);

private static final Map<String, Result<String>> EXCEPTION_DICTIONARY = new HashMap<>();

Expand Down Expand Up @@ -112,6 +114,8 @@ public class GlobalExceptionHandler {
// 6*.** 对应错误
EXCEPTION_DICTIONARY.put("BadSqlGrammarException", getResult(ResultStatus.BAD_SQL_GRAMMAR));
EXCEPTION_DICTIONARY.put("DataIntegrityViolationException", getResult(ResultStatus.DATA_INTEGRITY_VIOLATION));
EXCEPTION_DICTIONARY.put("BindException", getValidationResult(ResultStatus.METHOD_ARGUMENT_NOT_VALID));
EXCEPTION_DICTIONARY.put("MethodArgumentNotValidException", getValidationResult(ResultStatus.METHOD_ARGUMENT_NOT_VALID));
// 7*.** 对应错误
EXCEPTION_DICTIONARY.put("RedisPipelineException", getResult(ResultStatus.PIPELINE_INVALID_COMMANDS, HttpStatus.SC_INTERNAL_SERVER_ERROR));
// 以下是没有重新梳理过的错误。
Expand All @@ -136,9 +140,6 @@ public class GlobalExceptionHandler {

EXCEPTION_DICTIONARY.put("HttpMediaTypeNotAcceptableException", getBadRequestResult(ResultStatus.MEDIA_TYPE_NOT_ACCEPTABLE));
EXCEPTION_DICTIONARY.put("IllegalArgumentException", getBadRequestResult(ResultStatus.WARNING));


EXCEPTION_DICTIONARY.put("MethodArgumentNotValidException", getResult(ResultStatus.WARNING));
}


Expand All @@ -150,6 +151,10 @@ private static Result<String> getUnauthorizedResult(ResultStatus resultCode) {
return getResult(resultCode, HttpStatus.SC_UNAUTHORIZED);
}

private static Result<String> getValidationResult(ResultStatus resultCode) {
return getResult(resultCode, HttpStatus.SC_NOT_ACCEPTABLE);
}

private static Result<String> getResult(ResultStatus resultCode) {
return getResult(resultCode, HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
Expand All @@ -174,8 +179,8 @@ public static Result<String> resolveException(Exception ex, String path) {
}

result.path(path);
result.error(ex);
result.data(ex.getMessage());
result.stackTrace(new StackTraceElement[]{});
result.detail(ex.getMessage());

log.debug("[Eurynome] |- Global Exception Handler, Error is : {}", result);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2021 Gengwei Zheng([email protected])
* Copyright (c) 2019-2021 Gengwei Zheng ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,13 +14,13 @@
* limitations under the License.
*
* Project Name: eurynome-cloud
* Module Name: eurynome-cloud-common
* Module Name: eurynome-cloud-assistant
* File Name: IllegalArgumentException.java
* Author: gengwei.zheng
* Date: 2021/05/07 11:28:07
* Date: 2021/08/18 17:52:18
*/

package cn.herodotus.eurynome.common.exception;
package cn.herodotus.eurynome.assistant.exception.platform;

/**
* <p> Description : 非法参数错误 </p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2021 Gengwei Zheng([email protected])
* Copyright (c) 2019-2021 Gengwei Zheng ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,15 +14,15 @@
* limitations under the License.
*
* Project Name: eurynome-cloud
* Module Name: eurynome-cloud-common
* Module Name: eurynome-cloud-assistant
* File Name: PlatformException.java
* Author: gengwei.zheng
* Date: 2021/05/07 11:28:07
* Date: 2021/08/18 17:52:18
*/

package cn.herodotus.eurynome.common.exception;
package cn.herodotus.eurynome.assistant.exception.platform;

import cn.herodotus.eurynome.constant.enums.ResultStatus;
import cn.herodotus.eurynome.common.constant.enums.ResultStatus;

/**
* <p>Description: 平台基础Exception </p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

package cn.herodotus.eurynome.assistant.utils;

import cn.herodotus.eurynome.constant.magic.PlatformConstants;
import cn.herodotus.eurynome.constant.magic.PropertyConstants;
import cn.herodotus.eurynome.common.constant.magic.PlatformConstants;
import cn.herodotus.eurynome.common.constant.magic.PropertyConstants;
import org.springframework.core.env.Environment;

/**
Expand Down
44 changes: 38 additions & 6 deletions packages/eurynome-cloud-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,16 @@
<parent>
<artifactId>packages</artifactId>
<groupId>cn.herodotus.eurynome</groupId>
<version>2.5.4.50</version>
<version>2.5.4.55</version>
</parent>

<artifactId>eurynome-cloud-common</artifactId>
<version>2.5.4.50</version>
<version>2.5.4.55</version>
<packaging>jar</packaging>

<description>结对基础通用的工具类包,此包的定位是放在任何工程中都可以使用,而且尽可能依赖少的存在上下文组件</description>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>eurynome-cloud-constant</artifactId>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
Expand Down Expand Up @@ -85,7 +81,43 @@
<artifactId>guava</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<exclusions>
<exclusion>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
</dependency>

<dependency>
<groupId>com.github.whvcse</groupId>
<artifactId>easy-captcha</artifactId>
</dependency>

<dependency>
<groupId>me.zhyd.oauth</groupId>
<artifactId>JustAuth</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Date: 2021/08/05 18:32:05
*/

package cn.herodotus.eurynome.constant.enums;
package cn.herodotus.eurynome.common.constant.enums;

/**
* <p>Description: TODO </p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Date: 2021/06/29 15:58:29
*/

package cn.herodotus.eurynome.constant.enums;
package cn.herodotus.eurynome.common.constant.enums;

import com.fasterxml.jackson.annotation.JsonValue;
import com.google.common.collect.ImmutableMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Date: 2021/06/29 15:58:29
*/

package cn.herodotus.eurynome.constant.enums;
package cn.herodotus.eurynome.common.constant.enums;

/**
* <p> Description : 用于区分是单体应用还是微服务应用 </p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Date: 2021/06/29 15:58:29
*/

package cn.herodotus.eurynome.constant.enums;
package cn.herodotus.eurynome.common.constant.enums;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Date: 2021/07/28 19:07:28
*/

package cn.herodotus.eurynome.constant.enums;
package cn.herodotus.eurynome.common.constant.enums;

/**
* <p>Description: 数据访问策略枚举类型 </p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
* Date: 2021/08/07 20:07:07
*/

package cn.herodotus.eurynome.constant.enums;
package cn.herodotus.eurynome.common.constant.enums;

import cn.herodotus.eurynome.constant.magic.SecurityConstants;
import cn.herodotus.eurynome.common.constant.magic.SecurityConstants;
import com.google.common.collect.ImmutableMap;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Date: 2021/08/14 06:50:14
*/

package cn.herodotus.eurynome.constant.enums;
package cn.herodotus.eurynome.common.constant.enums;

import com.google.common.collect.ImmutableMap;
import io.swagger.annotations.ApiModelProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Date: 2021/06/29 15:58:29
*/

package cn.herodotus.eurynome.constant.enums;
package cn.herodotus.eurynome.common.constant.enums;

/**
* <p>Description: Protocol枚举 </p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Date: 2021/06/29 15:58:29
*/

package cn.herodotus.eurynome.constant.enums;
package cn.herodotus.eurynome.common.constant.enums;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
Expand Down Expand Up @@ -81,6 +81,7 @@ public enum ResultStatus {
*/
BAD_SQL_GRAMMAR(6000, "低级SQL语法错误,检查SQL能否正常运行或者字段名称是否正确"),
DATA_INTEGRITY_VIOLATION(6200, "该数据正在被其它数据引用,请先删除引用关系,再进行数据删除操作"),
METHOD_ARGUMENT_NOT_VALID(6300, "接口参数校验错误"),

/**
* 7*.* 基础设施交互错误
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Date: 2021/06/29 15:58:29
*/

package cn.herodotus.eurynome.constant.enums;
package cn.herodotus.eurynome.common.constant.enums;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Date: 2021/05/07 11:28:07
*/

package cn.herodotus.eurynome.constant.enums.captcha;
package cn.herodotus.eurynome.common.constant.enums.captcha;

import com.wf.captcha.base.Captcha;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Date: 2021/05/07 11:28:07
*/

package cn.herodotus.eurynome.constant.enums.captcha;
package cn.herodotus.eurynome.common.constant.enums.captcha;

import com.wf.captcha.base.Captcha;

Expand Down
Loading

0 comments on commit fd9096b

Please sign in to comment.