# -*- coding: utf-8 -*- """requests 同形异常层次(同步 HTTP 门面 core.sync_http 使用)。 历史:`core.aiohttp_compat`(异步垫片)与 `core.sync_http`(同步门面)曾各自 定义一份 `RequestException` / `HTTPError`——两份定义互不相干,于是同一条调用链上 「同步段抛的异常捕获不到异步段的同类失败」。异步垫片已删除、其调用方(music_api) 全面改走 core.http_client(自带 UpstreamError 层次);此处保留唯一来源, 供仍在线程里同步取数据的 core.sync_http 使用。 命名沿用 requests(`Timeout` / `ConnectionError` 与内置异常同名,这是 requests 自身的约定——调用方应带模块前缀引用,例如 `requests.ConnectionError`, 裸 `ConnectionError` 会命中内置的那个)。 层次: RequestException 网络 / 协议层失败(可捕获的总入口) ├── HTTPError raise_for_status() 抛出的状态异常(携带 response) ├── Timeout 请求超时 └── ConnectionError 连接错误 """ from typing import Any class RequestException(Exception): """请求异常基类(网络/协议层)。""" class HTTPError(RequestException): """raise_for_status() 抛出的 HTTP 状态异常。""" def __init__(self, message: str, response: Any = None): super().__init__(message) self.response = response class Timeout(RequestException): """请求超时。""" class ConnectionError(RequestException): """连接错误。"""