This commit is contained in:
2025-10-23 18:28:17 +02:00
parent 9a64ca5b01
commit 3d5c19939c
5 changed files with 277 additions and 96 deletions

View File

@@ -209,6 +209,11 @@ class EnhancedAniWorldLoader(Loader):
elif response.status_code == 403:
raise NonRetryableError(f"Access forbidden: {url}")
elif response.status_code >= 500:
# Log suspicious server errors for monitoring
self.logger.warning(
f"Server error {response.status_code} from {url} "
f"- will retry"
)
raise RetryableError(f"Server error {response.status_code}")
else:
raise RetryableError(f"HTTP error {response.status_code}")
@@ -225,6 +230,18 @@ class EnhancedAniWorldLoader(Loader):
clean_text = response_text.strip()
# Quick fail for obviously non-JSON responses
if not (clean_text.startswith('[') or clean_text.startswith('{')):
# Check if it's HTML error page
if clean_text.lower().startswith('<!doctype') or \
clean_text.lower().startswith('<html'):
raise ValueError("Received HTML instead of JSON")
# If doesn't start with JSON markers, likely not JSON
self.logger.warning(
"Response doesn't start with JSON markers, "
"attempting parse anyway"
)
# Attempt increasingly permissive parsing strategies to cope with
# upstream anomalies such as HTML escaping, stray BOM markers, and
# injected control characters.