1
0

GlobalExceptionHandler.java 783 B

12345678910111213141516171819202122
  1. package com.seecoder.BlueWhale.Exception;
  2. import com.seecoder.BlueWhale.VO.ResultVO;
  3. import org.springframework.web.bind.annotation.ExceptionHandler;
  4. import org.springframework.web.bind.annotation.RestControllerAdvice;
  5. /**
  6. * @Author: DingXiaoyu
  7. * @Date: 0:26 2023/11/26
  8. * 这个类能够接住项目中所有抛出的异常,
  9. * 使用了RestControllerAdvice切面完成,
  10. * 表示所有异常出现后都会通过这里。
  11. * 这个类将异常信息封装到ResultVO中进行返回。
  12. */
  13. @RestControllerAdvice
  14. public class GlobalExceptionHandler {
  15. @ExceptionHandler(value = BlueWhaleException.class)
  16. public ResultVO<String> handleAIExternalException(BlueWhaleException e) {
  17. e.printStackTrace();
  18. return ResultVO.buildFailure(e.getMessage());
  19. }
  20. }