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 2062cc96
authored
Jun 16, 2023
by
丁伟峰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
for test
1 parent
738f0ceb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
1 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
View file @
2062cc9
package
com
.
alibaba
.
cloud
.
integration
.
order
.
controller
;
package
com
.
alibaba
.
cloud
.
integration
.
order
.
controller
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.validation.BindException
;
import
com.alibaba.cloud.integration.common.Result
;
import
com.alibaba.cloud.integration.common.Result
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.validation.FieldError
;
import
org.springframework.validation.FieldError
;
...
@@ -7,6 +8,7 @@ import org.springframework.web.bind.MethodArgumentNotValidException;
...
@@ -7,6 +8,7 @@ import org.springframework.web.bind.MethodArgumentNotValidException;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
import
java.util.Objects
;
import
java.util.Objects
;
...
@@ -14,6 +16,16 @@ import java.util.Objects;
...
@@ -14,6 +16,16 @@ import java.util.Objects;
@Slf4j
@Slf4j
public
class
GlobalExceptionHandler
{
public
class
GlobalExceptionHandler
{
// 处理 BindException 异常
@ExceptionHandler
(
BindException
.
class
)
@ResponseStatus
(
HttpStatus
.
BAD_REQUEST
)
// 可选:设置响应状态码
@ResponseBody
public
Result
<?>
handleBindException
(
BindException
ex
)
{
// 处理异常并返回自定义的错误信息
log
.
error
(
"======== xxxxxxxxxxx ====> {}"
,
ex
.
toString
());
return
Result
.
failed
(
"请求参数验证失败:"
+
ex
.
getMessage
());
}
@ExceptionHandler
(
Exception
.
class
)
@ExceptionHandler
(
Exception
.
class
)
@ResponseBody
@ResponseBody
public
Result
<?>
handleException
(
Exception
e
)
{
public
Result
<?>
handleException
(
Exception
e
)
{
...
...
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