Commit 50e01da1acb974af9c67380850d7777865303b38
1 parent
626c40ad
refactor(config):重构全局异常处理器并迁移至中央配置模块
- 将 GlobalExceptionHandler 从 tax-storage 模块迁移到 tax-central 配置模块- 更新包名为 com.diligrp.tax.central.config- 将注解从 @ControllerAdvice 更改为 @RestControllerAdvice - 移除对 NoHandlerFoundException 和 NoResourceFoundException 的异常处理方法- 调整类文件路径以匹配新的模块结构
Showing
1 changed file
with
3 additions
and
28 deletions
tax-storage/src/main/java/com/diligrp/tax/storage/GlobalExceptionHandler.java renamed to tax-central/src/main/java/com/diligrp/tax/central/config/GlobalExceptionHandler.java
| 1 | -package com.diligrp.tax.storage; | |
| 1 | +package com.diligrp.tax.central.config; | |
| 2 | 2 | |
| 3 | 3 | import com.diligrp.tax.central.exception.TaxAgentServiceException; |
| 4 | 4 | import com.diligrp.tax.central.type.TaxSystemType; |
| ... | ... | @@ -16,8 +16,7 @@ import org.springframework.web.bind.MethodArgumentNotValidException; |
| 16 | 16 | import org.springframework.web.bind.MissingServletRequestParameterException; |
| 17 | 17 | import org.springframework.web.bind.annotation.ControllerAdvice; |
| 18 | 18 | import org.springframework.web.bind.annotation.ExceptionHandler; |
| 19 | -import org.springframework.web.servlet.NoHandlerFoundException; | |
| 20 | -import org.springframework.web.servlet.resource.NoResourceFoundException; | |
| 19 | +import org.springframework.web.bind.annotation.RestControllerAdvice; | |
| 21 | 20 | |
| 22 | 21 | import java.util.List; |
| 23 | 22 | import java.util.Set; |
| ... | ... | @@ -26,7 +25,7 @@ import java.util.stream.Collectors; |
| 26 | 25 | /** |
| 27 | 26 | * 统一异常处理器 |
| 28 | 27 | */ |
| 29 | -@ControllerAdvice | |
| 28 | +@RestControllerAdvice | |
| 30 | 29 | @Slf4j |
| 31 | 30 | public class GlobalExceptionHandler { |
| 32 | 31 | /** |
| ... | ... | @@ -118,28 +117,4 @@ public class GlobalExceptionHandler { |
| 118 | 117 | log.error("unknown error :", ex); |
| 119 | 118 | return Message.failure(TaxSystemType.UNKNOWN_ERROR.code, TaxSystemType.UNKNOWN_ERROR.message); |
| 120 | 119 | } |
| 121 | - | |
| 122 | - /** | |
| 123 | - * 未找到处理程序异常处理程序 | |
| 124 | - * | |
| 125 | - * @param ex 系统异常 | |
| 126 | - * @return 响应消息对象 | |
| 127 | - */ | |
| 128 | - @ExceptionHandler(NoHandlerFoundException.class) | |
| 129 | - public Message<?> NoHandlerFoundExceptionHandler(NoHandlerFoundException ex) { | |
| 130 | - log.error("no handler found exception :", ex); | |
| 131 | - return Message.failure(TaxSystemType.NOT_FOUND.code, TaxSystemType.NOT_FOUND.message); | |
| 132 | - } | |
| 133 | - | |
| 134 | - /** | |
| 135 | - * 未找到处理程序异常处理程序 | |
| 136 | - * | |
| 137 | - * @param ex 系统异常 | |
| 138 | - * @return 响应消息对象 | |
| 139 | - */ | |
| 140 | - @ExceptionHandler(NoResourceFoundException.class) | |
| 141 | - public Message<?> NoResourceFoundExceptionHandler(NoResourceFoundException ex) { | |
| 142 | - log.error("no resource found exception :", ex); | |
| 143 | - return Message.failure(TaxSystemType.NOT_FOUND.code, TaxSystemType.NOT_FOUND.message); | |
| 144 | - } | |
| 145 | 120 | } | ... | ... |