From 70f2803dd3c22892c7d67585ed142115d3c8768c Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Mon, 30 Mar 2026 21:41:37 +0200 Subject: [PATCH] fix(prospecting): handle PageSpeed API errors and improve performance card MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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) --- .../services/enrichment_service.py | 14 ++++++++ .../prospecting/admin/prospect-detail.html | 34 ++++++++++++++----- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/app/modules/prospecting/services/enrichment_service.py b/app/modules/prospecting/services/enrichment_service.py index e4a7a251..a8f787f7 100644 --- a/app/modules/prospecting/services/enrichment_service.py +++ b/app/modules/prospecting/services/enrichment_service.py @@ -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", {}) diff --git a/app/modules/prospecting/templates/prospecting/admin/prospect-detail.html b/app/modules/prospecting/templates/prospecting/admin/prospect-detail.html index 1b1287e9..5c33d50e 100644 --- a/app/modules/prospecting/templates/prospecting/admin/prospect-detail.html +++ b/app/modules/prospecting/templates/prospecting/admin/prospect-detail.html @@ -162,23 +162,39 @@
{{ section_header('Performance', icon='chart-bar') }} -
+ +
+ Scan failed: + +
+ +
- Performance Score + Performance + x-text="prospect.performance_profile?.performance_score + '/100'"> +
+
+ Accessibility + +
+
+ Best Practices + +
+
+ SEO +
Mobile Friendly -
-
- SEO Score - -
+

No performance data — configure PAGESPEED_API_KEY in .env