Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
schbrain-parent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
panwangnan
schbrain-parent
Commits
cf4fb49e
Commit
cf4fb49e
authored
Apr 27, 2023
by
liaozan
🏀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update DefaultGlobalExceptionHandler
parent
182a2a2c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
11 deletions
+14
-11
commons/web-common/src/main/java/com/schbrain/common/web/exception/DefaultGlobalExceptionHandler.java
...n/common/web/exception/DefaultGlobalExceptionHandler.java
+14
-11
No files found.
commons/web-common/src/main/java/com/schbrain/common/web/exception/DefaultGlobalExceptionHandler.java
View file @
cf4fb49e
...
...
@@ -2,6 +2,7 @@ package com.schbrain.common.web.exception;
import
cn.hutool.core.exceptions.ExceptionUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.schbrain.common.constants.ResponseActionConstants
;
import
com.schbrain.common.exception.BaseException
;
import
com.schbrain.common.util.EnvUtils
;
import
com.schbrain.common.web.result.ResponseDTO
;
...
...
@@ -40,7 +41,8 @@ public class DefaultGlobalExceptionHandler implements GlobalExceptionHandler {
/************************************* Base Exception Handing *************************************/
@ExceptionHandler
(
BaseException
.
class
)
public
ResponseDTO
<
String
>
handleBaseException
(
BaseException
ex
)
{
return
loggingThenBuildResponse
(
ex
,
ex
.
getCode
());
log
.
error
(
ex
.
getMessage
());
return
buildResponse
(
ex
,
ex
.
getCode
(),
ex
.
getAction
(),
ex
.
getMessage
());
}
/************************************* Common Exception Handing *************************************/
...
...
@@ -197,22 +199,23 @@ public class DefaultGlobalExceptionHandler implements GlobalExceptionHandler {
return
buildResponse
(
rootCause
,
errorCode
,
rootCause
.
getMessage
());
}
protected
ResponseDTO
<
String
>
buildResponse
(
Throwable
throwable
,
int
errorCode
,
String
message
)
{
boolean
production
=
EnvUtils
.
isProduction
();
ResponseDTO
<
String
>
responseDTO
=
getExceptionResponseMapping
(
throwable
,
production
);
protected
ResponseDTO
<
String
>
buildResponse
(
Throwable
throwable
,
int
code
,
String
message
)
{
return
buildResponse
(
throwable
,
code
,
ResponseActionConstants
.
ALERT
,
message
);
}
protected
ResponseDTO
<
String
>
buildResponse
(
Throwable
throwable
,
int
code
,
int
action
,
String
message
)
{
boolean
isProduction
=
EnvUtils
.
isProduction
();
ResponseDTO
<
String
>
responseDTO
=
getExceptionResponseMapping
(
throwable
,
isProduction
);
if
(
responseDTO
!=
null
)
{
return
responseDTO
;
}
if
(
production
)
{
return
ResponseDTO
.
error
(
"系统错误"
,
errorCode
);
}
if
(
StringUtils
.
isBlank
(
message
))
{
return
ResponseDTO
.
error
(
"系统错误"
,
errorCode
);
if
(
isProduction
||
StringUtils
.
isBlank
(
message
))
{
return
ResponseDTO
.
error
(
"系统错误"
,
code
,
action
);
}
return
ResponseDTO
.
error
(
message
,
errorCode
);
return
ResponseDTO
.
error
(
message
,
code
,
action
);
}
protected
ResponseDTO
<
String
>
getExceptionResponseMapping
(
Throwable
throwable
,
boolean
p
roduction
)
{
protected
ResponseDTO
<
String
>
getExceptionResponseMapping
(
Throwable
throwable
,
boolean
isP
roduction
)
{
return
null
;
}
...
...
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