GlobalExceptionHandler.java 681 B

123456789101112131415161718192021222324
  1. package com.shs.official.common.exception;
  2. import com.shs.official.common.template.ResultTemplate;
  3. import org.springframework.web.bind.annotation.ControllerAdvice;
  4. import org.springframework.web.bind.annotation.ExceptionHandler;
  5. import org.springframework.web.bind.annotation.ResponseBody;
  6. import java.util.Map;
  7. /**
  8. * 全局异常
  9. *
  10. * @author SHS
  11. */
  12. @ControllerAdvice
  13. public class GlobalExceptionHandler {
  14. @ResponseBody
  15. @ExceptionHandler(BaseException.class)
  16. public Map<String, Object> handleCustomException(BaseException baseException) {
  17. return ResultTemplate.error(baseException.getCode(),baseException.getMessage(),baseException.getData());
  18. }
  19. }