IdempotentExceptionHandler.java 763 B

1234567891011121314151617181920212223242526
  1. package com.caimei.annotation;
  2. import com.caimei.model.ResponseJson;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.springframework.web.bind.annotation.ControllerAdvice;
  5. import org.springframework.web.bind.annotation.ExceptionHandler;
  6. import org.springframework.web.bind.annotation.ResponseBody;
  7. /**
  8. * ApI幂等异常处理
  9. *
  10. * @author : Charles
  11. * @date : 2021/3/29
  12. */
  13. @Slf4j
  14. @ControllerAdvice
  15. public class IdempotentExceptionHandler {
  16. @ExceptionHandler(IdempotentException.class)
  17. @ResponseBody
  18. public ResponseJson convertExceptionMsg(Exception e) {
  19. //自定义逻辑,可返回其他值
  20. log.error("ApI幂等错误拦截,错误信息:", e);
  21. return ResponseJson.error("幂等异常处理:" + e.getMessage());
  22. }
  23. }