This commit is contained in:
ddrwode
2026-02-27 17:36:31 +08:00
parent 19855500ab
commit db0fa81b2e
2 changed files with 58 additions and 21 deletions

View File

@@ -38,17 +38,38 @@ class TgeBrowserClient:
}
def _post(self, path: str, json: Optional[dict] = None) -> dict:
payload = json or {}
resp = requests.post(
f"{self.base_url}{path}",
headers=self._headers,
json=json or {},
json=payload,
timeout=30,
)
resp.raise_for_status()
if not resp.ok:
detail = (resp.text or "").strip()
try:
err = resp.json()
if isinstance(err, dict):
message = err.get("message") or err.get("msg") or ""
code = err.get("code")
if message:
detail = f"{message}; code={code}; body={err}"
elif detail:
detail = f"{detail}; body={err}"
else:
detail = str(err)
except Exception:
pass
if not detail:
detail = "无响应体"
raise RuntimeError(
f"TgeBrowser API HTTP {resp.status_code} POST {path} 失败: {detail}; payload={payload}"
)
data = resp.json()
if not data.get("success", False):
msg = data.get("message", "未知错误")
raise RuntimeError(f"TgeBrowser API 失败: {msg}")
raise RuntimeError(f"TgeBrowser API 失败: {msg}; body={data}; payload={payload}")
return data
def _get(self, path: str) -> dict:
@@ -57,11 +78,13 @@ class TgeBrowserClient:
headers=self._headers,
timeout=30,
)
resp.raise_for_status()
if not resp.ok:
detail = (resp.text or "").strip() or "无响应体"
raise RuntimeError(f"TgeBrowser API HTTP {resp.status_code} GET {path} 失败: {detail}")
data = resp.json()
if not data.get("success", False):
msg = data.get("message", "未知错误")
raise RuntimeError(f"TgeBrowser API 失败: {msg}")
raise RuntimeError(f"TgeBrowser API 失败: {msg}; body={data}")
return data
def status(self) -> dict: