Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
matrix
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
mall
arch
matrix
Commits
fe150613
Commit
fe150613
authored
Oct 17, 2019
by
qiuweili123
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加异常扩展
parent
13f5872b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
15 deletions
+59
-15
ProtocolExceptionHandler.java
protocol-starter/src/main/java/com/secoo/mall/common/handler/ProtocolExceptionHandler.java
+28
-15
AbsExceptionProcessor.java
protocol-starter/src/main/java/com/secoo/mall/common/processor/AbsExceptionProcessor.java
+14
-0
ExceptionProcessor.java
protocol-starter/src/main/java/com/secoo/mall/common/processor/ExceptionProcessor.java
+17
-0
No files found.
protocol-starter/src/main/java/com/secoo/mall/common/handler/ProtocolExceptionHandler.java
View file @
fe150613
...
@@ -4,8 +4,10 @@ import com.secoo.mall.common.core.errorcode.CommonErrorCode;
...
@@ -4,8 +4,10 @@ import com.secoo.mall.common.core.errorcode.CommonErrorCode;
import
com.secoo.mall.common.core.exception.BusinessException
;
import
com.secoo.mall.common.core.exception.BusinessException
;
import
com.secoo.mall.common.core.exception.ParameterException
;
import
com.secoo.mall.common.core.exception.ParameterException
;
import
com.secoo.mall.common.core.exception.SystemInternalException
;
import
com.secoo.mall.common.core.exception.SystemInternalException
;
import
com.secoo.mall.common.processor.ExceptionProcessor
;
import
com.secoo.mall.common.util.log.LoggerUtil
;
import
com.secoo.mall.common.util.log.LoggerUtil
;
import
com.secoo.mall.common.util.response.ResponseUtil
;
import
com.secoo.mall.common.util.response.ResponseUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.MessageSource
;
import
org.springframework.context.MessageSource
;
import
org.springframework.context.i18n.LocaleContextHolder
;
import
org.springframework.context.i18n.LocaleContextHolder
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
...
@@ -17,23 +19,34 @@ public class ProtocolExceptionHandler {
...
@@ -17,23 +19,34 @@ public class ProtocolExceptionHandler {
@Resource
@Resource
private
MessageSource
messageSource
;
private
MessageSource
messageSource
;
@ExceptionHandler
(
BusinessException
.
class
)
@Autowired
(
required
=
false
)
public
Object
businessExcepstionHandler
(
BusinessException
e
)
{
private
ExceptionProcessor
exceptionProcessor
;
LoggerUtil
.
warn
(
"businessException info:"
,
e
);
return
ResponseUtil
.
getFailResponse
(
e
.
getCode
(),
getMsg
(
e
));
}
@ExceptionHandler
(
ParameterException
.
class
)
public
Object
parameterExceptionHandler
(
ParameterException
e
)
{
String
msg
=
getMsg
(
e
);
LoggerUtil
.
info
(
msg
);
return
ResponseUtil
.
getFailResponse
(
e
.
getCode
(),
msg
);
}
@ExceptionHandler
({
SystemInternalException
.
class
,
Exception
.
class
})
@ExceptionHandler
({
Exception
.
class
})
public
Object
exceptionHandler
(
Exception
e
)
{
public
Object
exceptionHandler
(
Exception
e
)
{
LoggerUtil
.
error
(
e
);
try
{
return
ResponseUtil
.
getFailResponse
(
CommonErrorCode
.
SYSTEM_INTERNAL_EXCEPTION
.
getCode
(),
CommonErrorCode
.
SYSTEM_INTERNAL_EXCEPTION
.
getMsg
());
if
(
exceptionProcessor
==
null
)
{
throw
e
;
}
exceptionProcessor
.
process
(
e
);
}
catch
(
ParameterException
ex
)
{
String
msg
=
getMsg
(
ex
);
LoggerUtil
.
info
(
msg
);
return
ResponseUtil
.
getFailResponse
(
ex
.
getCode
(),
msg
);
}
catch
(
SystemInternalException
ex
)
{
LoggerUtil
.
error
(
e
);
return
ResponseUtil
.
getFailResponse
(
CommonErrorCode
.
SYSTEM_INTERNAL_EXCEPTION
.
getCode
(),
CommonErrorCode
.
SYSTEM_INTERNAL_EXCEPTION
.
getMsg
());
}
catch
(
BusinessException
ex
)
{
LoggerUtil
.
warn
(
"businessException info:"
,
ex
);
return
ResponseUtil
.
getFailResponse
(
ex
.
getCode
(),
getMsg
(
ex
));
}
catch
(
Exception
ex
)
{
LoggerUtil
.
error
(
ex
);
return
ResponseUtil
.
getFailResponse
(
CommonErrorCode
.
SYSTEM_INTERNAL_EXCEPTION
.
getCode
(),
CommonErrorCode
.
SYSTEM_INTERNAL_EXCEPTION
.
getMsg
());
}
return
null
;
}
}
...
...
protocol-starter/src/main/java/com/secoo/mall/common/processor/AbsExceptionProcessor.java
0 → 100644
View file @
fe150613
package
com
.
secoo
.
mall
.
common
.
processor
;
public
abstract
class
AbsExceptionProcessor
implements
ExceptionProcessor
{
public
void
process
(
Exception
e
)
throws
Exception
{
convertException
(
e
);
throw
e
;
}
protected
abstract
void
convertException
(
Exception
e
);
}
protocol-starter/src/main/java/com/secoo/mall/common/processor/ExceptionProcessor.java
0 → 100644
View file @
fe150613
package
com
.
secoo
.
mall
.
common
.
processor
;
import
com.secoo.mall.common.core.errorcode.ErrorCode
;
import
com.secoo.mall.common.core.exception.BusinessException
;
import
com.secoo.mall.common.util.spring.SpringUtil
;
import
java.util.Map
;
public
interface
ExceptionProcessor
{
/**
* 处理异常
* @param e
* @return
*/
void
process
(
Exception
e
)
throws
Exception
;
}
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