CustomExceptionHandler.java 863 B

123456789101112131415161718192021222324
  1. package com.toolpage.toolpageservice.ToolPageController;
  2. import com.toolpage.toolpageservice.tool.RW;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.springframework.web.bind.annotation.ExceptionHandler;
  5. import org.springframework.web.bind.annotation.RestControllerAdvice;
  6. import reactor.core.publisher.Mono;
  7. @Slf4j
  8. @RestControllerAdvice
  9. public class CustomExceptionHandler {
  10. @ExceptionHandler(Exception.class)
  11. public Mono<RW<Object>> handleCustomException(Exception e) {
  12. log.info("捕获到未处理的Exception异常:{}",e);
  13. return RW.fail("9999",Mono.just(e.getMessage()));
  14. }
  15. // @ExceptionHandler(BusinessException.class)
  16. // public Mono<RW<Object>> handleBusinessException(BusinessException e) {
  17. // log.info("捕获到BusinessException异常:{}",e);
  18. // return RW.fail(e.getCode(),e.getMessage());
  19. // }
  20. }