Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
liyeyun-user-web
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cfld-backend
liyeyun-user-web
Commits
b01f6e32
Commit
b01f6e32
authored
Dec 05, 2023
by
yaobaizheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
校验异常信息太臃肿 简化一下
parent
300e1368
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
1 deletion
+5
-1
GlobalExceptionHandler.java
...com/lyy/user/config/exception/GlobalExceptionHandler.java
+5
-1
No files found.
src/main/java/com/lyy/user/config/exception/GlobalExceptionHandler.java
View file @
b01f6e32
...
@@ -2,11 +2,13 @@ package com.lyy.user.config.exception;
...
@@ -2,11 +2,13 @@ package com.lyy.user.config.exception;
import
com.lyy.user.util.AjaxResult
;
import
com.lyy.user.util.AjaxResult
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.validation.ObjectError
;
import
org.springframework.web.bind.MethodArgumentNotValidException
;
import
org.springframework.web.bind.MethodArgumentNotValidException
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
import
javax.validation.ValidationException
;
import
javax.validation.ValidationException
;
import
java.util.stream.Collectors
;
/**
/**
* @author: zhouxudong
* @author: zhouxudong
...
@@ -32,7 +34,9 @@ public class GlobalExceptionHandler {
...
@@ -32,7 +34,9 @@ public class GlobalExceptionHandler {
@ExceptionHandler
(
value
=
MethodArgumentNotValidException
.
class
)
@ExceptionHandler
(
value
=
MethodArgumentNotValidException
.
class
)
public
AjaxResult
handlerException
(
MethodArgumentNotValidException
e
){
public
AjaxResult
handlerException
(
MethodArgumentNotValidException
e
){
log
.
error
(
"发生参数校验异常:"
,
e
);
log
.
error
(
"发生参数校验异常:"
,
e
);
return
AjaxResult
.
error
(
e
.
getMessage
());
String
error
=
e
.
getBindingResult
().
getAllErrors
().
stream
().
map
(
ObjectError:
:
getDefaultMessage
).
distinct
().
collect
(
Collectors
.
joining
(
";"
));
return
AjaxResult
.
error
(
error
);
// return AjaxResult.error(e.getMessage());
}
}
@ExceptionHandler
(
value
=
ServiceException
.
class
)
@ExceptionHandler
(
value
=
ServiceException
.
class
)
...
...
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