diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java index e29925f033..5439a91c14 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java @@ -6,30 +6,6 @@ package com.epmet.commons.tools.exception; * @Description: */ public enum EpmetErrorCode { - /*****************以下是框架自带的异常编码s****************************************************/ - INTERNAL_SERVER_ERROR (500,"服务器内部异常"), - UNAUTHORIZED (401,"未授权"), - FORBIDDEN (403,"拒绝访问,没有权限"), - NOT_NULL (10001,"{0}不能为空"), - DB_RECORD_EXISTS ( 10002,"数据库中已存在该记录"), - PARAMS_GET_ERROR ( 10003,"获取参数失败"), - ACCOUNT_PASSWORD_ERROR ( 10004,"账号或密码错误"), - ACCOUNT_DISABLE (10005,"账号已被停用"), - IDENTIFIER_NOT_NULL (10006,"唯一标识不能为空"), - CAPTCHA_ERROR (10007,"验证码不正确"), - SUB_MENU_EXIST (10008,"先删除子菜单或按钮"), - PASSWORD_ERROR (10009,"原密码不正确"), - ACCOUNT_NOT_EXIST (10010,"账号不存在"), - SUPERIOR_DEPT_ERROR ( 10011,"上级部门选择错误"), - SUPERIOR_MENU_ERROR (10012,"上级菜单不能为自身"), - DATA_SCOPE_PARAMS_ERROR (10013,"数据权限接口,只能是Map类型参数"), - DEPT_SUB_DELETE_ERROR (10014,"请先删除下级部门"), - DEPT_USER_DELETE_ERROR (10015,"请先删除部门下的用户"), - JSON_FORMAT_ERROR (10016,"参数格式不正确,请使用JSON格式"), - SUPERIOR_REGION_ERROR (10017,"上级区域选择错误"), - REGION_SUB_DELETE_ERROR (10018,"请先删除下级区域"), - /*****************以上是框架自带的错误编码****************************************************/ - SERVER_ERROR(8000, "服务器开小差了..."), CANNOT_JOIN_GROUP(8001, "只有认证党员和居民才可以加入小组,请选择您的身份"), CANNOT_CREATE_GROUP(8002, "只有党员和热心居民才能创建小组,请选择您的身份"), diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/RenException.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/RenException.java index 203acad9b0..b775eb8f9a 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/RenException.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/RenException.java @@ -1,14 +1,15 @@ /** * Copyright (c) 2018 人人开源 All rights reserved. - * + *
* https://www.renren.io - * + *
* 版权所有,侵权必究!
*/
package com.epmet.commons.tools.exception;
+import com.epmet.commons.tools.utils.MessageUtils;
import org.apache.commons.lang3.StringUtils;
/**
@@ -18,68 +19,82 @@ import org.apache.commons.lang3.StringUtils;
* @since 1.0.0
*/
public class RenException extends RuntimeException {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
private int code;
- private String msg;
-
- public RenException(int code) {
- this.code = code;
- this.msg = EpmetErrorCode.getMsg(code);
- }
-
- public RenException(int code, String... params) {
- this.code = code;
- this.msg = EpmetErrorCode.getMsg(code);
- }
-
- public RenException(int code, Throwable e) {
- super(e);
- this.code = code;
- this.msg = EpmetErrorCode.getMsg(code);
- }
-
- public RenException(int code, Throwable e, String... params) {
- super(e);
- this.code = code;
-
- }
-
- public RenException(int code, String msg){
- this.code = code;
- if(StringUtils.isBlank(msg)){
- this.msg = EpmetErrorCode.getMsg(code);
- }else{
- this.msg = msg;
- }
- }
-
-
- public RenException(String msg) {
- super(msg);
- this.code = EpmetErrorCode.SERVER_ERROR.getCode();
- this.msg = msg;
- }
-
- public RenException(String msg, Throwable e) {
- super(msg, e);
- this.code = EpmetErrorCode.SERVER_ERROR.getCode();
- this.msg = msg;
- }
+ private String msg;
- public String getMsg() {
- return msg;
- }
-
- public void setMsg(String msg) {
- this.msg = msg;
- }
-
- public int getCode() {
- return code;
- }
+ public RenException(int code) {
+ this.code = code;
+ this.msg = EpmetErrorCode.getMsg(code);
+ if (StringUtils.isBlank(this.msg)) {
+ this.msg = MessageUtils.getMessage(code);
+ }
+ }
- public void setCode(int code) {
- this.code = code;
- }
+ public RenException(int code, String... params) {
+ this.code = code;
+ this.msg = EpmetErrorCode.getMsg(code);
+ if (StringUtils.isBlank(this.msg)) {
+ this.msg = MessageUtils.getMessage(code, params);
+ }
+ }
+
+ public RenException(int code, Throwable e) {
+ super(e);
+ this.code = code;
+ this.msg = EpmetErrorCode.getMsg(code);
+ if (StringUtils.isBlank(this.msg)) {
+ this.msg = MessageUtils.getMessage(code);
+ }
+ }
+
+ public RenException(int code, Throwable e, String... params) {
+ super(e);
+ this.code = code;
+
+ }
+
+ public RenException(int code, String msg) {
+ this.code = code;
+ if (StringUtils.isBlank(msg)) {
+ this.msg = EpmetErrorCode.getMsg(code);
+ if (StringUtils.isBlank(this.msg)) {
+ this.msg = MessageUtils.getMessage(code, msg);
+ }
+ } else {
+ this.msg = msg;
+ }
+ }
+
+
+ public RenException(String msg) {
+ super(msg);
+// this.code = ErrorCode.INTERNAL_SERVER_ERROR;
+ this.code = EpmetErrorCode.SERVER_ERROR.getCode();
+ this.msg = msg;
+ }
+
+ public RenException(String msg, Throwable e) {
+ super(msg, e);
+// this.code = ErrorCode.INTERNAL_SERVER_ERROR;
+ this.code = EpmetErrorCode.SERVER_ERROR.getCode();
+ this.msg = msg;
+ }
+
+ public String getMsg() {
+ return msg;
+ }
+
+ public void setMsg(String msg) {
+ this.msg = msg;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ public void setCode(int code) {
+ this.code = code;
+ }
}
diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/Result.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/Result.java
index 96e74eb64f..f97f6f48db 100644
--- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/Result.java
+++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/Result.java
@@ -9,8 +9,10 @@
package com.epmet.commons.tools.utils;
import com.epmet.commons.tools.exception.EpmetErrorCode;
+import com.epmet.commons.tools.exception.ErrorCode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
+import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
@@ -56,6 +58,9 @@ public class Result