Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
midjourney-proxy
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
徐少华
midjourney-proxy
Commits
b0ea1b7b
Commit
b0ea1b7b
authored
Dec 12, 2018
by
田超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增异常统一处理
parent
d2b21c0d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
0 deletions
+22
-0
GlobalExceptionHandler.java
.../pcloud/common/core/exception/GlobalExceptionHandler.java
+22
-0
No files found.
pcloud-common-core/src/main/java/com/pcloud/common/core/exception/GlobalExceptionHandler.java
View file @
b0ea1b7b
...
@@ -9,7 +9,10 @@ import org.slf4j.LoggerFactory;
...
@@ -9,7 +9,10 @@ import org.slf4j.LoggerFactory;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.converter.HttpMessageNotReadableException
;
import
org.springframework.http.converter.HttpMessageNotReadableException
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.FieldError
;
import
org.springframework.web.HttpRequestMethodNotSupportedException
;
import
org.springframework.web.HttpRequestMethodNotSupportedException
;
import
org.springframework.web.bind.MethodArgumentNotValidException
;
import
org.springframework.web.bind.ServletRequestBindingException
;
import
org.springframework.web.bind.ServletRequestBindingException
;
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
;
...
@@ -22,6 +25,8 @@ import com.pcloud.common.permission.PermissionException;
...
@@ -22,6 +25,8 @@ import com.pcloud.common.permission.PermissionException;
import
feign.FeignException
;
import
feign.FeignException
;
import
org.springframework.web.method.annotation.MethodArgumentTypeMismatchException
;
import
org.springframework.web.method.annotation.MethodArgumentTypeMismatchException
;
import
java.util.List
;
/**
/**
*
*
* @描述:异常集中处理
* @描述:异常集中处理
...
@@ -92,6 +97,23 @@ public class GlobalExceptionHandler {
...
@@ -92,6 +97,23 @@ public class GlobalExceptionHandler {
LOGGER
.
warn
(
"【响应未结束】"
+
exception
.
getMessage
(),
exception
);
LOGGER
.
warn
(
"【响应未结束】"
+
exception
.
getMessage
(),
exception
);
return
new
ResponseEntity
<>(
"响应未结束!"
,
HttpStatus
.
OK
);
return
new
ResponseEntity
<>(
"响应未结束!"
,
HttpStatus
.
OK
);
}
}
else
if
(
exception
instanceof
MethodArgumentNotValidException
)
{
LOGGER
.
info
(
"【参数异常】"
+
exception
.
getMessage
(),
exception
);
MethodArgumentNotValidException
methodArgumentNotValidException
=
(
MethodArgumentNotValidException
)
exception
;
ResponseDto
<
Object
>
responseDto
=
new
ResponseDto
<>();
BindingResult
bindingResult
=
methodArgumentNotValidException
.
getBindingResult
();
String
resultMessage
=
"参数异常:"
;
List
<
FieldError
>
fieldErrors
=
bindingResult
.
getFieldErrors
();
for
(
int
i
=
0
;
i
<
fieldErrors
.
size
();
i
++)
{
if
(
fieldErrors
.
size
()==
1
||
i
==
fieldErrors
.
size
()-
1
){
resultMessage
+=
fieldErrors
.
get
(
i
).
getDefaultMessage
();
}
else
{
resultMessage
+=
fieldErrors
.
get
(
i
).
getDefaultMessage
()
+
", "
;
}
}
responseDto
.
setMessage
(
resultMessage
);
return
new
ResponseEntity
<>(
responseDto
,
HttpStatus
.
OK
);
}
// 业务异常
// 业务异常
else
if
(
exception
instanceof
BizException
)
{
else
if
(
exception
instanceof
BizException
)
{
LOGGER
.
info
(
"【业务异常】"
+
exception
.
getMessage
(),
exception
);
LOGGER
.
info
(
"【业务异常】"
+
exception
.
getMessage
(),
exception
);
...
...
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