Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
6723d6d8
Commit
6723d6d8
authored
Aug 13, 2022
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
升级新版本
parent
bcb26273
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
45 deletions
+73
-45
ExceptionHelper.java
.../java/com/yanzuoguang/util/exception/ExceptionHelper.java
+9
-6
ResponseResult.java
...src/main/java/com/yanzuoguang/util/vo/ResponseResult.java
+63
-34
AspectFeign.java
.../src/main/java/com/yanzuoguang/cloud/aop/AspectFeign.java
+1
-5
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/exception/ExceptionHelper.java
View file @
6723d6d8
...
...
@@ -64,19 +64,22 @@ public class ExceptionHelper {
* @return 返回的数据
*/
public
static
ResponseResult
<?>
getError
(
Exception
e
,
boolean
isFull
)
{
if
(
e
instanceof
CodeTargetException
)
{
CodeTargetException
code
=
(
CodeTargetException
)
e
;
return
getError
(
code
.
getCode
(),
code
.
getMessage
(),
code
.
getTarget
(),
true
);
}
else
if
(
e
instanceof
RuntimeCodeException
)
{
boolean
isFullTo
=
e
instanceof
CodeTargetException
||
isFull
;
boolean
codeError
=
e
instanceof
CodeException
;
ResponseResult
<?>
result
;
if
(
e
instanceof
RuntimeCodeException
)
{
RuntimeCodeException
code
=
(
RuntimeCodeException
)
e
;
re
turn
getError
(
code
.
getCode
(),
code
.
getMessage
(),
code
.
getTarget
(),
isFull
);
re
sult
=
getError
(
code
.
getCode
(),
code
.
getMessage
(),
code
.
getTarget
(),
isFullTo
);
}
else
{
String
msg
=
e
.
getMessage
();
if
(
StringHelper
.
isEmpty
(
msg
))
{
msg
=
e
.
getClass
().
getName
();
}
re
turn
getError
(
ResultConstants
.
UNKNOW_ERROR
,
msg
,
e
,
isFull
);
re
sult
=
getError
(
ResultConstants
.
UNKNOW_ERROR
,
msg
,
e
,
isFullTo
);
}
result
.
setCodeError
(
codeError
);
return
result
;
}
private
static
ResponseResult
<?>
getError
(
String
code
,
String
msg
,
Object
target
,
boolean
isFull
)
{
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/vo/ResponseResult.java
View file @
6723d6d8
...
...
@@ -2,6 +2,7 @@ package com.yanzuoguang.util.vo;
import
com.yanzuoguang.util.contants.ResultConstants
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.exception.RuntimeCodeException
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
io.swagger.annotations.ApiModelProperty
;
...
...
@@ -37,6 +38,54 @@ public class ResponseResult<T> extends BaseVo {
*/
@ApiModelProperty
(
value
=
"异常数据"
,
notes
=
"当抛出异常时的数据,通常和code进行组合"
,
required
=
true
)
private
Object
target
;
/**
* 是否是code错误
*/
@ApiModelProperty
(
value
=
"异常数据"
,
notes
=
"当抛出异常时的数据,通常和code进行组合"
,
required
=
true
)
private
boolean
codeError
=
false
;
/**
* 构造函数
*/
public
ResponseResult
()
{
this
(
ResultConstants
.
SUCCESS
,
"操作成功"
);
}
/**
* 构造函数
*
* @param code 结果状态
* @param message 结果消息
*/
public
ResponseResult
(
String
code
,
String
message
)
{
this
(
code
,
message
,
null
);
}
/**
* 构造函数
*
* @param code 结果状态
* @param message 结果熊希
* @param data 结果
*/
public
ResponseResult
(
String
code
,
String
message
,
T
data
)
{
this
(
code
,
message
,
data
,
null
);
}
/**
* 构造函数
*
* @param code 结果状态
* @param message 结果熊希
* @param data 结果
*/
public
ResponseResult
(
String
code
,
String
message
,
T
data
,
Object
target
)
{
this
.
code
=
code
;
this
.
message
=
message
;
this
.
data
=
data
;
this
.
target
=
target
;
}
/**
* 检查数据是否合法,不合法则抛出异常,合法则返回数据
...
...
@@ -45,7 +94,12 @@ public class ResponseResult<T> extends BaseVo {
if
(
StringHelper
.
compare
(
code
,
ResultConstants
.
SUCCESS
))
{
return
this
.
data
;
}
throw
new
CodeException
(
this
.
code
,
this
.
message
,
this
.
target
);
if
(
this
.
codeError
)
{
throw
new
CodeException
(
this
.
code
,
this
.
message
,
this
.
target
);
}
else
{
throw
new
RuntimeCodeException
(
this
.
code
,
this
.
message
,
this
.
target
);
}
}
/**
...
...
@@ -121,46 +175,21 @@ public class ResponseResult<T> extends BaseVo {
}
/**
* 构造函数
*/
public
ResponseResult
()
{
this
(
ResultConstants
.
SUCCESS
,
"操作成功"
);
}
/**
* 构造函数
* 是否是code错误
*
* @param code 结果状态
* @param message 结果消息
* @return 是否是code错误
*/
public
ResponseResult
(
String
code
,
String
message
)
{
this
(
code
,
message
,
null
)
;
public
boolean
isCodeError
(
)
{
return
codeError
;
}
/**
* 构造函数
*
* @param code 结果状态
* @param message 结果熊希
* @param data 结果
*/
public
ResponseResult
(
String
code
,
String
message
,
T
data
)
{
this
(
code
,
message
,
data
,
null
);
}
/**
* 构造函数
* 设置code错误
*
* @param code 结果状态
* @param message 结果熊希
* @param data 结果
* @param codeError code错误
*/
public
ResponseResult
(
String
code
,
String
message
,
T
data
,
Object
target
)
{
this
.
code
=
code
;
this
.
message
=
message
;
this
.
data
=
data
;
this
.
target
=
target
;
public
void
setCodeError
(
boolean
codeError
)
{
this
.
codeError
=
codeError
;
}
/**
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/AspectFeign.java
View file @
6723d6d8
package
com
.
yanzuoguang
.
cloud
.
aop
;
import
com.yanzuoguang.util.contants.ResultConstants
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.exception.ExceptionHelper
;
import
com.yanzuoguang.util.vo.LogVo
;
...
...
@@ -67,11 +66,8 @@ public class AspectFeign {
// 假如是标准格式,则验证接口是否成功,不成功则抛出异常
if
(
result
instanceof
ResponseResult
)
{
ResponseResult
<?>
responseResult
=
(
ResponseResult
<?>)
result
;
if
(!
ResultConstants
.
SUCCESS
.
equals
(
responseResult
.
getCode
()))
{
throw
new
CodeException
(
responseResult
.
getCode
(),
responseResult
.
getMessage
(),
responseResult
.
getTarget
());
}
responseResult
.
check
();
}
return
result
;
}
catch
(
CodeException
e
)
{
ex
=
e
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment