mirror of
https://github.com/xr843/Master-skill.git
synced 2026-05-10 13:26:25 +00:00
feat: graceful degradation when FoJin API is unavailable (P0)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+20
-4
@@ -7,12 +7,18 @@ Two modes:
|
||||
"""
|
||||
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
from typing import Optional
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
class FojinUnavailableError(Exception):
|
||||
"""Raised when FoJin API is unreachable. Callers should handle gracefully."""
|
||||
pass
|
||||
|
||||
|
||||
class FojinBridge:
|
||||
"""Bridge to FoJin Buddhist text platform."""
|
||||
|
||||
@@ -108,11 +114,21 @@ class FojinBridge:
|
||||
# ── Helpers ──────────────────────────────────────────────
|
||||
|
||||
def _get(self, path: str, params: Optional[dict] = None) -> dict:
|
||||
"""Make GET request to FoJin API."""
|
||||
"""Make GET request to FoJin API.
|
||||
|
||||
Raises:
|
||||
FojinUnavailableError: When FoJin is unreachable (connection/timeout)
|
||||
requests.HTTPError: On 4xx/5xx responses
|
||||
"""
|
||||
url = f"{self.base_url}{path}"
|
||||
resp = self.session.get(url, params=params, timeout=30)
|
||||
resp.raise_for_status()
|
||||
return resp.json()
|
||||
try:
|
||||
resp = self.session.get(url, params=params, timeout=30)
|
||||
resp.raise_for_status()
|
||||
return resp.json()
|
||||
except requests.ConnectionError as e:
|
||||
raise FojinUnavailableError(f"FoJin API unreachable: {e}") from e
|
||||
except requests.Timeout as e:
|
||||
raise FojinUnavailableError(f"FoJin API timeout: {e}") from e
|
||||
|
||||
def test_connection(self) -> bool:
|
||||
"""Test if FoJin API is reachable."""
|
||||
|
||||
Reference in New Issue
Block a user