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
aee91ed5
Commit
aee91ed5
authored
Aug 10, 2021
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改实例化关系
parent
b0a6d5b7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
154 additions
and
42 deletions
+154
-42
YzgError.java
...til-base/src/main/java/com/yanzuoguang/util/YzgError.java
+42
-42
YzgErrorData.java
...base/src/main/java/com/yanzuoguang/util/YzgErrorData.java
+112
-0
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/YzgError.java
View file @
aee91ed5
package
com
.
yanzuoguang
.
util
;
package
com
.
yanzuoguang
.
util
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.util.exception.RuntimeCodeException
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
/**
* 系统错误编码
* 系统错误编码
...
@@ -14,27 +10,34 @@ import java.util.Map;
...
@@ -14,27 +10,34 @@ import java.util.Map;
*/
*/
public
class
YzgError
{
public
class
YzgError
{
/**
private
static
YzgErrorData
error
=
new
YzgErrorData
(
"999."
);
* 错误标记
*/
public
static
final
String
TAG
=
"999."
;
/**
* 错误缓存消息
*/
private
static
Map
<
String
,
String
>
ErrorCode
=
new
HashMap
<>();
private
static
void
init
()
{
private
static
void
init
()
{
add
(
"001"
,
""
);
error
.
add
(
"001"
,
""
);
}
}
private
static
void
initTemp
()
{
private
static
void
initTemp
()
{
}
/**
* 抛出异常
*
* @param code
* @param args
*/
public
static
CodeException
throwException
(
String
code
,
Object
...
args
)
{
throw
error
.
getCodeException
(
null
,
code
,
args
);
}
}
public
static
void
add
(
String
code
,
String
message
)
{
/**
ErrorCode
.
put
(
code
,
message
);
* 抛出异常
*
* @param code
* @param args
*/
public
CodeException
throwException
(
Exception
ex
,
String
code
,
Object
...
args
)
{
throw
error
.
getCodeException
(
ex
,
code
,
args
);
}
}
/**
/**
...
@@ -43,8 +46,8 @@ public class YzgError {
...
@@ -43,8 +46,8 @@ public class YzgError {
* @param code
* @param code
* @param args
* @param args
*/
*/
public
static
CodeException
throw
Exception
(
String
code
,
Object
...
args
)
{
public
CodeException
get
Exception
(
String
code
,
Object
...
args
)
{
throw
get
Exception
(
null
,
code
,
args
);
return
error
.
getCode
Exception
(
null
,
code
,
args
);
}
}
/**
/**
...
@@ -53,8 +56,8 @@ public class YzgError {
...
@@ -53,8 +56,8 @@ public class YzgError {
* @param code
* @param code
* @param args
* @param args
*/
*/
public
static
CodeException
throw
Exception
(
Exception
ex
,
String
code
,
Object
...
args
)
{
public
CodeException
get
Exception
(
Exception
ex
,
String
code
,
Object
...
args
)
{
throw
get
Exception
(
ex
,
code
,
args
);
return
error
.
getCode
Exception
(
ex
,
code
,
args
);
}
}
/**
/**
...
@@ -63,8 +66,8 @@ public class YzgError {
...
@@ -63,8 +66,8 @@ public class YzgError {
* @param code
* @param code
* @param args
* @param args
*/
*/
public
static
CodeException
get
Exception
(
String
code
,
Object
...
args
)
{
public
RuntimeCodeException
throwRuntime
Exception
(
String
code
,
Object
...
args
)
{
return
get
Exception
(
null
,
code
,
args
);
throw
error
.
getRuntime
Exception
(
null
,
code
,
args
);
}
}
/**
/**
...
@@ -73,8 +76,8 @@ public class YzgError {
...
@@ -73,8 +76,8 @@ public class YzgError {
* @param code
* @param code
* @param args
* @param args
*/
*/
public
static
CodeException
get
Exception
(
Exception
ex
,
String
code
,
Object
...
args
)
{
public
RuntimeCodeException
throwRuntime
Exception
(
Exception
ex
,
String
code
,
Object
...
args
)
{
return
getException
(
ErrorCode
,
TAG
,
ex
,
code
,
args
);
throw
error
.
getRuntimeException
(
ex
,
code
,
args
);
}
}
/**
/**
...
@@ -83,24 +86,21 @@ public class YzgError {
...
@@ -83,24 +86,21 @@ public class YzgError {
* @param code
* @param code
* @param args
* @param args
*/
*/
public
static
CodeException
getException
(
Map
<
String
,
String
>
ErrorCode
,
String
tag
,
Exception
ex
,
String
code
,
Object
...
args
)
{
public
RuntimeCodeException
getRuntimeException
(
String
code
,
Object
...
args
)
{
String
message
=
ErrorCode
.
get
(
code
);
return
error
.
getRuntimeException
(
null
,
code
,
args
);
if
(
StringHelper
.
isEmpty
(
message
))
{
message
=
"未知错误"
+
JsonHelper
.
serialize
(
args
);
}
else
{
try
{
message
=
String
.
format
(
message
,
args
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
if
(
ex
!=
null
)
{
return
new
CodeException
(
tag
+
code
,
message
,
ex
);
}
else
{
return
new
CodeException
(
tag
+
code
,
message
);
}
}
}
/**
* 抛出异常
*
* @param code
* @param args
*/
public
RuntimeCodeException
getRuntimeException
(
Exception
ex
,
String
code
,
Object
...
args
)
{
return
error
.
getRuntimeException
(
ex
,
code
,
args
);
}
static
{
static
{
init
();
init
();
initTemp
();
initTemp
();
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/YzgErrorData.java
0 → 100644
View file @
aee91ed5
package
com
.
yanzuoguang
.
util
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.exception.RuntimeCodeException
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 错误处理
*
* @author 颜佐光
*/
public
class
YzgErrorData
{
/**
* 错误标记
*/
public
String
TAG
=
StringHelper
.
EMPTY
;
/**
* 错误缓存消息
*/
private
Map
<
String
,
String
>
ErrorCode
=
new
HashMap
<>();
public
YzgErrorData
(
String
TAG
)
{
this
.
TAG
=
TAG
;
}
/**
* 添加错误信息
*
* @param code 错误编码
* @param message 错误消息
*/
public
void
add
(
String
code
,
String
message
)
{
ErrorCode
.
put
(
code
,
message
);
}
/**
* 抛出异常
*
* @param code
* @param args
*/
public
CodeException
getCodeException
(
String
code
,
Object
...
args
)
{
return
getCodeException
(
null
,
code
,
args
);
}
/**
* 抛出异常
*
* @param code
* @param args
*/
public
CodeException
getCodeException
(
Exception
ex
,
String
code
,
Object
...
args
)
{
String
message
=
getMessage
(
ErrorCode
,
code
,
args
);
if
(
ex
!=
null
)
{
return
new
CodeException
(
TAG
+
code
,
message
,
ex
);
}
else
{
return
new
CodeException
(
TAG
+
code
,
message
);
}
}
/**
* 抛出异常
*
* @param code
* @param args
*/
public
RuntimeCodeException
getRuntimeException
(
String
code
,
Object
...
args
)
{
return
getRuntimeException
(
null
,
code
,
args
);
}
/**
* 抛出异常
*
* @param code
* @param args
*/
public
RuntimeCodeException
getRuntimeException
(
Exception
ex
,
String
code
,
Object
...
args
)
{
String
message
=
getMessage
(
ErrorCode
,
code
,
args
);
if
(
ex
!=
null
)
{
return
new
RuntimeCodeException
(
TAG
+
code
,
message
,
ex
);
}
else
{
return
new
RuntimeCodeException
(
TAG
+
code
,
message
);
}
}
/**
* 获取异常消息
*
* @param errorCode
* @param code
* @param args
* @return
*/
public
String
getMessage
(
Map
<
String
,
String
>
errorCode
,
String
code
,
Object
...
args
)
{
String
message
=
errorCode
.
get
(
code
);
if
(
StringHelper
.
isEmpty
(
message
))
{
message
=
"未知错误"
+
JsonHelper
.
serialize
(
args
);
}
else
{
try
{
message
=
String
.
format
(
message
,
args
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
return
message
;
}
}
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