Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
yangxiujun
/
paidan_demo
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 86b4965f
authored
Jun 15, 2023
by
丁伟峰
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feat-dingwf-mvp616' into develop
2 parents
fa5589d1
4f0aff28
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
0 deletions
project-order/src/main/java/com/alibaba/cloud/integration/order/controller/GlobalExceptionHandler.java
project-order/src/main/java/com/alibaba/cloud/integration/order/controller/GlobalExceptionHandler.java
0 → 100644
View file @
86b4965
package
com
.
alibaba
.
cloud
.
integration
.
order
.
controller
;
import
com.alibaba.cloud.integration.common.Result
;
import
org.springframework.validation.BindException
;
import
org.springframework.validation.ObjectError
;
import
org.springframework.web.bind.MethodArgumentNotValidException
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
import
javax.validation.ConstraintViolation
;
import
javax.validation.ConstraintViolationException
;
import
javax.validation.ValidationException
;
import
java.util.stream.Collectors
;
@RestControllerAdvice
public
class
GlobalExceptionHandler
{
@ExceptionHandler
(
value
=
{
BindException
.
class
,
ValidationException
.
class
,
MethodArgumentNotValidException
.
class
})
public
Result
<?>
handleValidatedException
(
Exception
e
)
{
Result
<?>
resp
=
null
;
if
(
e
instanceof
MethodArgumentNotValidException
)
{
// BeanValidation exception
MethodArgumentNotValidException
ex
=
(
MethodArgumentNotValidException
)
e
;
resp
=
Result
.
failed
(
ex
.
getBindingResult
().
getAllErrors
().
stream
()
.
map
(
ObjectError:
:
getDefaultMessage
)
.
collect
(
Collectors
.
joining
(
"; "
))
);
}
else
if
(
e
instanceof
ConstraintViolationException
)
{
// BeanValidation GET simple param
ConstraintViolationException
ex
=
(
ConstraintViolationException
)
e
;
resp
=
Result
.
failed
(
ex
.
getConstraintViolations
().
stream
()
.
map
(
ConstraintViolation:
:
getMessage
)
.
collect
(
Collectors
.
joining
(
"; "
))
);
}
else
if
(
e
instanceof
BindException
)
{
// BeanValidation GET object param
BindException
ex
=
(
BindException
)
e
;
resp
=
Result
.
failed
(
ex
.
getAllErrors
().
stream
()
.
map
(
ObjectError:
:
getDefaultMessage
)
.
collect
(
Collectors
.
joining
(
"; "
))
);
}
else
{
resp
=
Result
.
failed
(
"其他错误信息,这个逻辑应该不会走到 ~~~ "
);
}
return
resp
;
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment