记得上下班打卡 | git大法好,push需谨慎
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liquidnet-bus-v1
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
董敬伟
liquidnet-bus-v1
Commits
075773f6
Commit
075773f6
authored
Jul 27, 2022
by
张国柄
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
~ex.handler;
parent
0b7228e0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
5 deletions
+11
-5
RestControllerAdviceHandler.java
...quidnet/common/exception/RestControllerAdviceHandler.java
+11
-5
No files found.
liquidnet-bus-common/liquidnet-common-exception/liquidnet-common-exception-handler-service/src/main/java/com/liquidnet/common/exception/RestControllerAdviceHandler.java
View file @
075773f6
...
...
@@ -9,6 +9,7 @@ import com.liquidnet.common.exception.constant.ErrorCode;
import
com.liquidnet.common.exception.entity.Error
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.converter.HttpMessageNotReadableException
;
...
...
@@ -36,25 +37,30 @@ import javax.validation.ConstraintViolationException;
@ControllerAdvice
(
annotations
=
RestController
.
class
)
public
class
RestControllerAdviceHandler
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
RestControllerAdviceHandler
.
class
);
@Value
(
"${spring.profiles.active:prod}"
)
private
String
active
;
@ExceptionHandler
(
value
=
Exception
.
class
)
@ResponseBody
public
ResponseEntity
<
Error
>
serviceExceptionHandler
(
Exception
rex
,
HttpServletRequest
req
)
{
logger
.
error
(
"Ex.Handler.RestController:uri:{},param:{},ex:{},msg:{},"
,
re
q
.
getRequestURI
(),
JSON
.
toJSONString
(
req
.
getParameterMap
()),
rex
.
getClass
().
getSimpleName
(),
rex
.
getLocalized
Message
());
logger
.
warn
(
"Ex.Rest[uri:{},param:{},ex:{},msg:{}]"
,
req
.
getRequestURI
(),
JSON
.
toJSONString
(
req
.
getParameterMap
())
,
re
x
.
getClass
().
getSimpleName
(),
rex
.
get
Message
());
if
(
rex
instanceof
HttpMessageNotReadableException
)
{
return
new
ResponseEntity
<>(
Error
.
getNew
().
setCode
(
ErrorCode
.
HTTP_PARAM_ERROR
.
getCode
()).
setMessage
(
ErrorCode
.
HTTP_PARAM_ERROR
.
getMessage
()),
HttpStatus
.
OK
);
}
if
(
rex
instanceof
MissingServletRequestParameterException
)
{
MissingServletRequestParameterException
ygex
=
(
MissingServletRequestParameterException
)
rex
;
String
message
=
ygex
.
getMessage
();
String
message
=
ErrorCode
.
HTTP_PARAM_ERROR
.
getMessage
();
if
(!
"prod"
.
equals
(
active
))
{
MissingServletRequestParameterException
ygex
=
(
MissingServletRequestParameterException
)
rex
;
message
=
ygex
.
getMessage
();
}
return
new
ResponseEntity
<>(
Error
.
getNew
().
setCode
(
ErrorCode
.
HTTP_PARAM_ERROR
.
getCode
()).
setMessage
(
message
),
HttpStatus
.
OK
);
}
if
(
rex
instanceof
ConstraintViolationException
)
{
ConstraintViolationException
ygex
=
(
ConstraintViolationException
)
rex
;
ConstraintViolation
violation
=
(
ConstraintViolation
)
ygex
.
getConstraintViolations
().
toArray
()[
0
];
String
violationNode
=
violation
.
getPropertyPath
().
toString
();
//
String violationNode = violation.getPropertyPath().toString();
// String message = violationNode.substring(violationNode.indexOf(".") + 1) + violation.getMessage();
String
message
=
violation
.
getMessage
();
return
new
ResponseEntity
<>(
Error
.
getNew
().
setCode
(
ErrorCode
.
HTTP_PARAM_ERROR
.
getCode
()).
setMessage
(
message
),
HttpStatus
.
OK
);
...
...
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