"""mipu_requests 异常类 — 兼容 requests 异常命名""" class RequestException(Exception): """基异常(对应 requests.exceptions.RequestException)""" pass class APIError(RequestException): """Bluebird API 返回非零 code""" def __init__(self, response): self.response = response code = response.get("code", "?") if isinstance(response, dict) else "?" msg = response.get("msg", "") if isinstance(response, dict) else str(response) super().__init__(f"API error: code={code}, msg={msg}") class HTTPError(RequestException): """目标网站返回 HTTP 错误状态码(对应 requests.exceptions.HTTPError)""" def __init__(self, response): self.response = response super().__init__(f"{response.status_code} for {response.url}") class PollTimeoutError(RequestException): """异步轮询超时""" def __init__(self, agent_request_id, max_attempts=0): self.agent_request_id = agent_request_id self.max_attempts = max_attempts super().__init__(f"Poll timeout after {max_attempts} attempts for {agent_request_id}")