Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
traffic-signal-platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
jinan
traffic-signal-platform
Commits
14e359ba
Commit
14e359ba
authored
Mar 26, 2025
by
duanruiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[add] 统一异常处理
parent
f1e13a8a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
0 deletions
+26
-0
OptExceptionHandler.java
...a/net/wanji/opt/common/exception/OptExceptionHandler.java
+12
-0
pom.xml
wj-common/pom.xml
+4
-0
GlobalExceptionHandler.java
...on/framework/exceptionhandler/GlobalExceptionHandler.java
+10
-0
No files found.
signal-optimize-service/src/main/java/net/wanji/opt/common/exception/OptExceptionHandler.java
View file @
14e359ba
package
net
.
wanji
.
opt
.
common
.
exception
;
import
lombok.extern.slf4j.Slf4j
;
import
net.wanji.common.framework.exceptionhandler.GlobalExceptionHandler
;
import
net.wanji.common.framework.rest.JsonViewObject
;
import
org.apache.catalina.connector.ClientAbortException
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
/**
...
...
@@ -12,6 +16,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
* @date 2023/1/5 13:18
*/
@RestControllerAdvice
@Slf4j
public
class
OptExceptionHandler
extends
GlobalExceptionHandler
{
/**
* 字段值重复异常
...
...
@@ -25,4 +30,11 @@ public class OptExceptionHandler extends GlobalExceptionHandler {
public
JsonViewObject
OptServiceExceptionHandler
(
OptServiceException
e
)
{
return
JsonViewObject
.
newInstance
().
fail
(
e
.
getMessage
(),
"optService服务调用异常"
);
}
@ExceptionHandler
(
value
=
ClientAbortException
.
class
)
@ResponseStatus
(
HttpStatus
.
OK
)
public
JsonViewObject
clientExceptionHandler
(
ClientAbortException
ex
)
{
log
.
error
(
"ClientAbortException异常opt:{}"
,
ex
);
return
JsonViewObject
.
newInstance
().
success
(
""
);
}
}
\ No newline at end of file
wj-common/pom.xml
View file @
14e359ba
...
...
@@ -556,6 +556,10 @@
<artifactId>
curl
</artifactId>
<version>
0.0.43
</version>
</dependency>
<dependency>
<groupId>
org.apache.tomcat.embed
</groupId>
<artifactId>
tomcat-embed-core
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
wj-common/src/main/java/net/wanji/common/framework/exceptionhandler/GlobalExceptionHandler.java
View file @
14e359ba
...
...
@@ -5,11 +5,14 @@ import net.wanji.common.framework.Constants;
import
net.wanji.common.framework.exception.FeignServiceException
;
import
net.wanji.common.framework.exception.RidException
;
import
net.wanji.common.framework.rest.JsonViewObject
;
import
org.apache.catalina.connector.ClientAbortException
;
import
org.springframework.dao.DuplicateKeyException
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.converter.HttpMessageNotReadableException
;
import
org.springframework.validation.FieldError
;
import
org.springframework.web.bind.MethodArgumentNotValidException
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
import
javax.servlet.http.HttpServletRequest
;
...
...
@@ -170,4 +173,11 @@ public class GlobalExceptionHandler {
log
.
error
(
"RuntimeException异常:"
,
e
);
return
JsonViewObject
.
newInstance
().
fail
(
errorMessage
);
}
@ExceptionHandler
(
value
=
ClientAbortException
.
class
)
@ResponseStatus
(
HttpStatus
.
OK
)
public
JsonViewObject
clientExceptionHandler
(
ClientAbortException
ex
)
{
log
.
error
(
"ClientAbortException异常global:{}"
,
ex
);
return
JsonViewObject
.
newInstance
().
success
(
""
);
}
}
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