fix(prospecting): handle PageSpeed API errors and improve performance card
- Detect API-level errors (quota exceeded, invalid URL) in response JSON and store in scan_error instead of silently writing zeros - Show scan error message on the performance card when present - Show "No performance data — configure PAGESPEED_API_KEY" when all scores are 0 and no error was recorded - Add accessibility and best practices scores to performance card Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -210,6 +210,20 @@ class EnrichmentService:
|
||||
response = requests.get(api_url, params=params, timeout=60)
|
||||
data = response.json()
|
||||
|
||||
# Check for API-level errors (quota exceeded, invalid URL, etc.)
|
||||
if "error" in data:
|
||||
error_msg = data["error"].get("message", str(data["error"]))
|
||||
logger.warning("PageSpeed API error for %s: %s", domain, error_msg)
|
||||
profile = prospect.performance_profile
|
||||
if not profile:
|
||||
profile = ProspectPerformanceProfile(prospect_id=prospect.id)
|
||||
db.add(profile)
|
||||
profile.scan_error = error_msg
|
||||
profile.scan_strategy = "mobile"
|
||||
prospect.last_perf_scan_at = datetime.now(UTC)
|
||||
db.flush()
|
||||
return profile
|
||||
|
||||
lighthouse = data.get("lighthouseResult", {})
|
||||
categories = lighthouse.get("categories", {})
|
||||
audits = lighthouse.get("audits", {})
|
||||
|
||||
Reference in New Issue
Block a user