ApiPanic.java 911 B

12345678910111213141516171819202122232425
  1. package com.mokamrp.privates.config;
  2. import com.mokamrp.privates.utils.Cmd;
  3. import org.springframework.beans.factory.annotation.Value;
  4. import org.springframework.stereotype.Component;
  5. import org.springframework.web.bind.annotation.ControllerAdvice;
  6. import org.springframework.web.bind.annotation.ExceptionHandler;
  7. @ControllerAdvice
  8. public class ApiPanic {
  9. private final String feishu = "https://open.feishu.cn/open-apis/bot/v2/hook/538d8993-e23a-4836-863c-05515b41160e";
  10. @Value("${spring.profiles.active}")
  11. private String env;
  12. @ExceptionHandler(value = Exception.class)
  13. public String exceptionHandler(Exception e) {
  14. if (env.equals("prod")) {
  15. //.正式环境捕获API异常 推送到飞书
  16. if (e.getMessage() != null){
  17. Cmd.sendFeishuMsg(feishu, "[moka-private]:api panic " + e);
  18. }
  19. }
  20. return e.getMessage();
  21. }
  22. }