Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gic-enterprise-base
Overview
Overview
Details
Activity
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
base_platform_enterprise
gic-enterprise-base
Commits
1fa99af1
Commit
1fa99af1
authored
Jul 07, 2021
by
guojuxing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
全局异常类捕获还原代码
parent
fe52e528
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
0 deletions
+26
-0
GlobalExceptionHandler.java
.../com/gic/enterprise/exception/GlobalExceptionHandler.java
+26
-0
No files found.
gic-enterprise-common/src/main/java/com/gic/enterprise/exception/GlobalExceptionHandler.java
View file @
1fa99af1
...
@@ -29,6 +29,32 @@ public class GlobalExceptionHandler {
...
@@ -29,6 +29,32 @@ public class GlobalExceptionHandler {
private
static
Logger
logger
=
LogManager
.
getLogger
(
GlobalExceptionHandler
.
class
);
private
static
Logger
logger
=
LogManager
.
getLogger
(
GlobalExceptionHandler
.
class
);
/**
* 参数校验异常统一处理
* @param e
* @return
*/
@ExceptionHandler
(
BindException
.
class
)
public
RestResponse
customException
(
BindException
e
)
{
List
<
FieldError
>
fieldErrors
=
e
.
getFieldErrors
();
StringBuilder
errorMessage
=
new
StringBuilder
();
fieldErrors
.
forEach
(
fieldError
->
{
errorMessage
.
append
(
fieldError
.
getDefaultMessage
())
.
append
(
","
);
});
String
error
=
errorMessage
.
toString
();
return
getRestResponse
(
ErrorCode
.
PARAMETER_ERROR
.
getCode
(),
error
.
substring
(
0
,
error
.
length
()
-
1
));
}
@ExceptionHandler
(
ConstraintViolationException
.
class
)
public
RestResponse
constraintViolationException
(
ConstraintViolationException
e
)
{
Set
<
ConstraintViolation
<?>>
constraintViolations
=
e
.
getConstraintViolations
();
String
paramName
=
constraintViolations
.
iterator
().
next
().
getPropertyPath
().
toString
();
String
paramError
=
constraintViolations
.
iterator
().
next
().
getMessage
();
return
getRestResponse
(
ErrorCode
.
PARAMETER_ERROR
.
getCode
(),
getFailFastMsg
(
paramName
,
paramError
));
}
@ExceptionHandler
(
RuntimeException
.
class
)
@ExceptionHandler
(
RuntimeException
.
class
)
public
RestResponse
runtimeException
(
RuntimeException
e
){
public
RestResponse
runtimeException
(
RuntimeException
e
){
logger
.
warn
(
"异常:{}"
,
e
);
logger
.
warn
(
"异常:{}"
,
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