exception.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from enum import Enum
  2. from typing import NamedTuple
  3. from requests import RequestException
  4. class ErrorTuple(NamedTuple):
  5. code: int
  6. msg: str
  7. class ErrorEnum(Enum):
  8. IP_BLOCK = ErrorTuple(300012, "网络连接异常,请检查网络设置或重启试试")
  9. NOTE_ABNORMAL = ErrorTuple(-510001, "笔记状态异常,请稍后查看")
  10. NOTE_SECRETE_FAULT = ErrorTuple(-510001, "当前内容无法展示")
  11. SIGN_FAULT = ErrorTuple(300015, "浏览器异常,请尝试关闭/卸载风险插件或重启试试!")
  12. SESSION_EXPIRED = ErrorTuple(-100, "登录已过期")
  13. class DataFetchError(RequestException):
  14. """something error when fetch"""
  15. class IPBlockError(RequestException):
  16. """fetch so fast that the server block us ip"""
  17. class SignError(RequestException):
  18. """fetch error because x-s sign verror"""
  19. class NeedVerifyError(RequestException):
  20. """fetch error because need captcha"""
  21. def __init__(self, *args, **kwargs):
  22. self.verify_type = kwargs.pop("verify_type", None)
  23. self.verify_uuid = kwargs.pop("verify_uuid", None)
  24. super().__init__(*args, **kwargs)