Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cloud-backend
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
framework
cloud-backend
Commits
8d948e0a
Commit
8d948e0a
authored
Sep 13, 2024
by
袁伟铭
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化代码
parent
24faa4bc
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
6 deletions
+11
-6
xxx-common-utils/src/main/java/com/zq/common/config/base/UnifiedExceptionHandler.java
+11
-6
No files found.
xxx-common-utils/src/main/java/com/zq/common/config/base/UnifiedExceptionHandler.java
View file @
8d948e0a
...
@@ -60,12 +60,6 @@ public class UnifiedExceptionHandler {
...
@@ -60,12 +60,6 @@ public class UnifiedExceptionHandler {
return
ResultVo
.
fail
(
ex
.
getCode
(),
errMessage
);
return
ResultVo
.
fail
(
ex
.
getCode
(),
errMessage
);
}
}
@ExceptionHandler
(
MethodArgumentNotValidException
.
class
)
public
ResultVo
handleArgumentNotValidException
(
MethodArgumentNotValidException
ex
,
HttpServletRequest
request
)
{
log
.
warn
(
">> argument not valid error: {} {}"
,
request
.
getRequestURI
(),
ex
.
getMessage
());
return
ResultVo
.
fail
(
HttpStatus
.
BAD_REQUEST
.
value
(),
"无效的请求参数"
+
ex
.
getParameter
().
getParameterName
());
}
@ExceptionHandler
(
HttpRequestMethodNotSupportedException
.
class
)
@ExceptionHandler
(
HttpRequestMethodNotSupportedException
.
class
)
public
ResultVo
handleMethodNotSupportedException
(
HttpRequestMethodNotSupportedException
ex
,
HttpServletRequest
request
)
{
public
ResultVo
handleMethodNotSupportedException
(
HttpRequestMethodNotSupportedException
ex
,
HttpServletRequest
request
)
{
log
.
warn
(
">> method not supported error: {} {}, expected: {}"
,
log
.
warn
(
">> method not supported error: {} {}, expected: {}"
,
...
@@ -91,6 +85,17 @@ public class UnifiedExceptionHandler {
...
@@ -91,6 +85,17 @@ public class UnifiedExceptionHandler {
return
ResultVo
.
fail
(
HttpStatus
.
BAD_REQUEST
.
value
(),
"无法解析请求消息"
);
return
ResultVo
.
fail
(
HttpStatus
.
BAD_REQUEST
.
value
(),
"无法解析请求消息"
);
}
}
@ExceptionHandler
(
MethodArgumentNotValidException
.
class
)
public
ResultVo
handleArgumentNotValidException
(
MethodArgumentNotValidException
ex
,
HttpServletRequest
request
)
{
log
.
warn
(
">> argument not valid error: {} {}"
,
request
.
getRequestURI
(),
ex
.
getMessage
());
String
paranmName
=
ex
.
getParameter
().
getParameterName
();
List
<
FieldError
>
fieldErrors
=
ex
.
getBindingResult
().
getFieldErrors
();
if
(
CollUtil
.
isNotEmpty
(
fieldErrors
))
{
paranmName
=
fieldErrors
.
stream
().
map
(
f
->
"["
+
f
.
getDefaultMessage
()
+
"("
+
f
.
getField
()
+
")]"
).
collect
(
Collectors
.
joining
(
"、"
));
}
return
ResultVo
.
fail
(
HttpStatus
.
BAD_REQUEST
.
value
(),
"无效的请求参数:"
+
paranmName
);
}
@ExceptionHandler
({
MissingServletRequestPartException
.
class
,
MissingServletRequestParameterException
.
class
,
BindException
.
class
})
@ExceptionHandler
({
MissingServletRequestPartException
.
class
,
MissingServletRequestParameterException
.
class
,
BindException
.
class
})
public
ResultVo
handleMissingServletRequestPartException
(
Exception
ex
,
HttpServletRequest
request
)
{
public
ResultVo
handleMissingServletRequestPartException
(
Exception
ex
,
HttpServletRequest
request
)
{
log
.
warn
(
">> missing servlet request part/param error: {} {}"
,
request
.
getRequestURI
(),
ex
.
getMessage
());
log
.
warn
(
">> missing servlet request part/param error: {} {}"
,
request
.
getRequestURI
(),
ex
.
getMessage
());
...
...
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