mirror of
https://github.com/suyiiyii/SIMS.git
synced 2025-06-05 13:36:12 +08:00
fix(GlobalException): 在ServiceException处理中添加日志记录
在全局异常处理器中为ServiceException添加错误日志记录,以提高错误跟踪的可观察性。现在,当捕获到ServiceException时,将记录错误消息。 更改包含: - 导入lombok.extern.slf4j.Slf4j注解以启用日志记录功能。 - 使用@Slf4j注解GlobalException类。- 在ServiceException的@ExceptionHandler方法中添加日志记录语句。
This commit is contained in:
parent
bed21a1db0
commit
343aff9356
@ -1,5 +1,6 @@
|
|||||||
package top.suyiiyii.sims.exception;
|
package top.suyiiyii.sims.exception;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
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;
|
||||||
@ -13,11 +14,15 @@ import top.suyiiyii.sims.common.Result;
|
|||||||
* @Description: TODO
|
* @Description: TODO
|
||||||
* @Version 1.0
|
* @Version 1.0
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@ControllerAdvice
|
@ControllerAdvice
|
||||||
public class GlobalException {
|
public class GlobalException {
|
||||||
@ExceptionHandler(ServiceException.class)
|
@ExceptionHandler(ServiceException.class)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Result ServiceException(ServiceException e){
|
public Result ServiceException(ServiceException e) {
|
||||||
return Result.error(e.getCode(),e.getMessage());
|
log.warn("ServiceException:{}", e.getMessage());
|
||||||
|
// 打印错误调用栈
|
||||||
|
log.warn("ServiceException:", e);
|
||||||
|
return Result.error(e.getCode(), e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user