Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
guns-vip
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenjunxiong
guns-vip
Commits
a1c700f4
Commit
a1c700f4
authored
Mar 30, 2017
by
fsn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完成异常落库
parent
980d11c8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
1 deletions
+16
-1
src/main/java/com/stylefeng/guns/core/aop/GlobalExceptionHandler.java
+11
-0
src/main/java/com/stylefeng/guns/core/log/LogFactory.java
+5
-1
src/main/java/com/stylefeng/guns/core/util/ToolUtil.java
+0
-0
No files found.
src/main/java/com/stylefeng/guns/core/aop/GlobalExceptionHandler.java
View file @
a1c700f4
...
@@ -3,11 +3,15 @@ package com.stylefeng.guns.core.aop;
...
@@ -3,11 +3,15 @@ package com.stylefeng.guns.core.aop;
import
com.stylefeng.guns.common.constant.tips.ErrorTip
;
import
com.stylefeng.guns.common.constant.tips.ErrorTip
;
import
com.stylefeng.guns.common.exception.BizExceptionEnum
;
import
com.stylefeng.guns.common.exception.BizExceptionEnum
;
import
com.stylefeng.guns.common.exception.BussinessException
;
import
com.stylefeng.guns.common.exception.BussinessException
;
import
com.stylefeng.guns.core.log.ILog
;
import
com.stylefeng.guns.core.support.HttpKit
;
import
com.stylefeng.guns.core.support.HttpKit
;
import
com.stylefeng.guns.core.util.SpringContextHolder
;
import
com.stylefeng.guns.core.util.ToolUtil
;
import
org.apache.log4j.Logger
;
import
org.apache.log4j.Logger
;
import
org.apache.shiro.authc.AuthenticationException
;
import
org.apache.shiro.authc.AuthenticationException
;
import
org.apache.shiro.authc.CredentialsException
;
import
org.apache.shiro.authc.CredentialsException
;
import
org.apache.shiro.authc.DisabledAccountException
;
import
org.apache.shiro.authc.DisabledAccountException
;
import
org.springframework.context.annotation.DependsOn
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.ui.Model
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
...
@@ -24,10 +28,14 @@ import javax.naming.NoPermissionException;
...
@@ -24,10 +28,14 @@ import javax.naming.NoPermissionException;
* @date 2016年11月12日 下午3:19:56
* @date 2016年11月12日 下午3:19:56
*/
*/
@ControllerAdvice
@ControllerAdvice
@DependsOn
(
"springContextHolder"
)
public
class
GlobalExceptionHandler
{
public
class
GlobalExceptionHandler
{
private
Logger
log
=
Logger
.
getLogger
(
this
.
getClass
());
private
Logger
log
=
Logger
.
getLogger
(
this
.
getClass
());
private
ILog
logFactory
=
SpringContextHolder
.
getBean
(
ILog
.
class
);
/**
/**
* 拦截业务异常
* 拦截业务异常
*
*
...
@@ -37,6 +45,7 @@ public class GlobalExceptionHandler {
...
@@ -37,6 +45,7 @@ public class GlobalExceptionHandler {
@ResponseStatus
(
HttpStatus
.
INTERNAL_SERVER_ERROR
)
@ResponseStatus
(
HttpStatus
.
INTERNAL_SERVER_ERROR
)
@ResponseBody
@ResponseBody
public
ErrorTip
notFount
(
BussinessException
e
)
{
public
ErrorTip
notFount
(
BussinessException
e
)
{
logFactory
.
doLog
(
"业务异常"
,
e
.
toString
(),
false
);
HttpKit
.
getRequest
().
setAttribute
(
"tip"
,
e
.
getMessage
());
HttpKit
.
getRequest
().
setAttribute
(
"tip"
,
e
.
getMessage
());
return
new
ErrorTip
(
e
.
getCode
(),
e
.
getMessage
());
return
new
ErrorTip
(
e
.
getCode
(),
e
.
getMessage
());
}
}
...
@@ -50,6 +59,8 @@ public class GlobalExceptionHandler {
...
@@ -50,6 +59,8 @@ public class GlobalExceptionHandler {
@ResponseStatus
(
HttpStatus
.
INTERNAL_SERVER_ERROR
)
@ResponseStatus
(
HttpStatus
.
INTERNAL_SERVER_ERROR
)
@ResponseBody
@ResponseBody
public
ErrorTip
notFount
(
RuntimeException
e
)
{
public
ErrorTip
notFount
(
RuntimeException
e
)
{
String
msg
=
ToolUtil
.
getExceptionMsg
(
e
);
logFactory
.
doLog
(
"Runtime异常"
,
msg
,
false
);
log
.
error
(
"服务器异常:"
,
e
);
log
.
error
(
"服务器异常:"
,
e
);
HttpKit
.
getRequest
().
setAttribute
(
"tip"
,
"服务器未知运行时异常"
);
HttpKit
.
getRequest
().
setAttribute
(
"tip"
,
"服务器未知运行时异常"
);
return
new
ErrorTip
(
BizExceptionEnum
.
SERVER_ERROR
);
return
new
ErrorTip
(
BizExceptionEnum
.
SERVER_ERROR
);
...
...
src/main/java/com/stylefeng/guns/core/log/LogFactory.java
View file @
a1c700f4
...
@@ -30,6 +30,10 @@ public class LogFactory implements ILog {
...
@@ -30,6 +30,10 @@ public class LogFactory implements ILog {
log
.
setSucceed
((
succeed
)
?
"1"
:
"0"
);
log
.
setSucceed
((
succeed
)
?
"1"
:
"0"
);
log
.
setUserid
(
String
.
valueOf
(
user
.
getId
()));
log
.
setUserid
(
String
.
valueOf
(
user
.
getId
()));
log
.
setLogname
(
logName
);
log
.
setLogname
(
logName
);
operationLogMapper
.
insert
(
log
);
try
{
operationLogMapper
.
insert
(
log
);
}
catch
(
Exception
e
){
//e.printStackTrace();
}
}
}
}
}
src/main/java/com/stylefeng/guns/core/util/ToolUtil.java
View file @
a1c700f4
This diff is collapsed.
Click to expand it.
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