Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
usedCarAuction
/
aus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit f5f249c8
authored
Mar 20, 2026
by
章家宝
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat:删除没必要的代码
1 parent
b6f36e18
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1 additions
and
48 deletions
aus-admin/src/main/java/com/glsx/usedcar/advice/GlobalExceptionHandler.java
aus-inspector/src/main/java/com/glsx/usedcar/advice/GlobalExceptionHandler.java
aus-admin/src/main/java/com/glsx/usedcar/advice/GlobalExceptionHandler.java
deleted
100644 → 0
View file @
b6f36e1
package
com
.
glsx
.
usedcar
.
advice
;
import
com.glsx.usedcar.resp.BaseResp
;
import
lombok.extern.slf4j.Slf4j
;
import
org.hibernate.HibernateException
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.MethodArgumentNotValidException
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.stream.Collectors
;
/**
* 全局异常处理器,捕获所有Controller层未处理的异常
*/
@Slf4j
@RestControllerAdvice
public
class
GlobalExceptionHandler
{
// 捕获所有未指定的异常(兜底)
@ExceptionHandler
(
Exception
.
class
)
@ResponseStatus
(
HttpStatus
.
INTERNAL_SERVER_ERROR
)
// 明确返回500状态码
public
BaseResp
<
Void
>
handleAllUncaughtException
(
Exception
e
)
{
// 打印完整异常堆栈
log
.
error
(
"全局捕获未处理异常:"
,
e
);
// 返回标准化错误响应
return
BaseResp
.
fail
(
"服务器内部错误:"
+
e
.
getMessage
());
}
// 捕获参数校验异常(比如@Valid校验失败)
@ExceptionHandler
(
MethodArgumentNotValidException
.
class
)
@ResponseStatus
(
HttpStatus
.
BAD_REQUEST
)
public
BaseResp
<
Void
>
handleValidationException
(
MethodArgumentNotValidException
e
)
{
log
.
error
(
"参数校验失败:"
,
e
);
String
errorMsg
=
e
.
getBindingResult
().
getFieldErrors
().
stream
()
.
map
(
fieldError
->
fieldError
.
getField
()
+
":"
+
fieldError
.
getDefaultMessage
())
.
collect
(
Collectors
.
joining
(
","
));
return
BaseResp
.
fail
(
"参数错误:"
+
errorMsg
);
}
// 捕获JPA/Hibernate相关异常
@ExceptionHandler
(
HibernateException
.
class
)
@ResponseStatus
(
HttpStatus
.
INTERNAL_SERVER_ERROR
)
public
BaseResp
<
Void
>
handleHibernateException
(
HibernateException
e
)
{
log
.
error
(
"数据库查询异常:"
,
e
);
return
BaseResp
.
fail
(
"数据库操作失败:"
+
e
.
getMessage
());
}
}
\ No newline at end of file
\ No newline at end of file
aus-inspector/src/main/java/com/glsx/usedcar/advice/GlobalExceptionHandler.java
View file @
f5f249c
...
@@ -13,7 +13,7 @@ import java.util.stream.Collectors;
...
@@ -13,7 +13,7 @@ import java.util.stream.Collectors;
* 全局异常处理器,捕获所有Controller层未处理的异常
* 全局异常处理器,捕获所有Controller层未处理的异常
*/
*/
@Slf4j
@Slf4j
@RestControllerAdvice
// 作用于所有@RestController
@RestControllerAdvice
public
class
GlobalExceptionHandler
{
public
class
GlobalExceptionHandler
{
// 捕获所有未指定的异常(兜底)
// 捕获所有未指定的异常(兜底)
...
...
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