Files
real-time/src/main/java/com/realtime/config/GlobalException.java
2025-12-01 10:08:41 +08:00

28 lines
727 B
Java

package com.realtime.config;
import com.realtime.exception.BusinessException;
import com.realtime.sysconst.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@RestControllerAdvice
public class GlobalException {
@ExceptionHandler(BusinessException.class)
public Result<BusinessException> handle(BusinessException e) {
return Result.systemError(e.getMessage(),e.getCode());
}
/**
* 兜底异常
* @param e 异常
* @return 异常类型
*/
@ExceptionHandler(Exception.class)
public Result<String> exceptionHandler(Exception e) {
return Result.fail(e.getMessage());
}
}