Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform
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
youjj
cloud-platform
Commits
e2374f7e
Commit
e2374f7e
authored
Aug 19, 2019
by
jiaorz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
全局异常
parent
08135dcc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
1 deletion
+53
-1
GlobalBasicConfiguration.java
...curity/common/config/global/GlobalBasicConfiguration.java
+9
-0
GlobalExceptionHandler.java
...oqi/security/common/exception/GlobalExceptionHandler.java
+41
-0
CommonLogServiceImpl.java
...xiaoqi/security/common/log/Impl/CommonLogServiceImpl.java
+3
-1
No files found.
ace-common/src/main/java/com/github/wxiaoqi/security/common/config/global/GlobalBasicConfiguration.java
View file @
e2374f7e
package
com
.
github
.
wxiaoqi
.
security
.
common
.
config
.
global
;
package
com
.
github
.
wxiaoqi
.
security
.
common
.
config
.
global
;
import
com.github.wxiaoqi.security.common.exception.GlobalExceptionHandler
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.ApplicationArguments
;
import
org.springframework.boot.ApplicationArguments
;
import
org.springframework.boot.ApplicationRunner
;
import
org.springframework.boot.ApplicationRunner
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.env.Environment
;
...
@@ -13,6 +16,12 @@ public class GlobalBasicConfiguration implements ApplicationRunner{
...
@@ -13,6 +16,12 @@ public class GlobalBasicConfiguration implements ApplicationRunner{
private
static
Logger
log
=
LoggerFactory
.
getLogger
(
GlobalBasicConfiguration
.
class
);
private
static
Logger
log
=
LoggerFactory
.
getLogger
(
GlobalBasicConfiguration
.
class
);
private
static
Environment
env
;
private
static
Environment
env
;
@Bean
@ConditionalOnMissingBean
private
GlobalExceptionHandler
addGlobalExceptionHandler
()
{
return
new
GlobalExceptionHandler
();
}
@Autowired
@Autowired
private
void
setEnv
(
Environment
env
)
{
private
void
setEnv
(
Environment
env
)
{
GlobalBasicConfiguration
.
env
=
env
;
GlobalBasicConfiguration
.
env
=
env
;
...
...
ace-common/src/main/java/com/github/wxiaoqi/security/common/exception/GlobalExceptionHandler.java
0 → 100644
View file @
e2374f7e
package
com
.
github
.
wxiaoqi
.
security
.
common
.
exception
;
import
com.github.wxiaoqi.security.common.msg.ObjectRestResponse
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
/**
* 全局异常
*/
@RestControllerAdvice
@Slf4j
public
class
GlobalExceptionHandler
{
{
log
.
info
(
"[初始化成功] --- GlobalExceptionHandler"
);
}
protected
ObjectRestResponse
<?>
assembleResult
(
ObjectRestResponse
<?>
error
,
String
msg
)
{
log
.
debug
(
"Exception: "
+
msg
);
return
error
;
}
protected
ObjectRestResponse
<?>
assembleResult
(
ObjectRestResponse
<?>
error
,
Throwable
e
)
{
return
assembleResult
(
error
,
e
.
getClass
().
getSimpleName
()
+
": "
+
e
.
getMessage
());
}
//服务器异常
@ExceptionHandler
(
Exception
.
class
)
public
ObjectRestResponse
<?>
exceptionHandler
(
Exception
e
){
Throwable
cause
=
e
.
getCause
();
if
(
cause
!=
null
&&
cause
.
toString
().
contains
(
"com.netflix.client.ClientException"
))
{
log
.
error
(
cause
.
getMessage
(),
e
);
return
assembleResult
(
ObjectRestResponse
.
createFailedResult
(
5000
,
"服务器开小差了,请稍后重试!"
),
"Server exception: "
+
e
.
getMessage
());
}
log
.
error
(
"Server exception: "
,
e
);
return
assembleResult
(
ObjectRestResponse
.
createFailedResult
(
5000
,
"服务器开小差了,请稍后重试!"
),
"Server exception: "
+
e
.
getMessage
());
}
}
\ No newline at end of file
ace-common/src/main/java/com/github/wxiaoqi/security/common/log/Impl/CommonLogServiceImpl.java
View file @
e2374f7e
...
@@ -88,7 +88,9 @@ public class CommonLogServiceImpl implements CommonLogService {
...
@@ -88,7 +88,9 @@ public class CommonLogServiceImpl implements CommonLogService {
}
}
@Override
@Override
public
void
run
()
{
public
void
run
()
{
log
.
info
(
"用户请求信息:xxLogEntity = {}"
,
xxLogEntity
.
toString
());
if
(!
xxLogEntity
.
getServletPath
().
contains
(
"/vehicleInfo/app/unauth/getVehiclePlanList"
))
{
log
.
info
(
"用户请求信息:xxLogEntity = {}"
,
xxLogEntity
.
toString
());
}
mongoTemplate
.
insert
(
xxLogEntity
,
xxLogEntity
.
getMongoKey
());
mongoTemplate
.
insert
(
xxLogEntity
,
xxLogEntity
.
getMongoKey
());
}
}
}
}
...
...
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