From 89c31f829818693fcedd66ba7fe6b4fb87614121 Mon Sep 17 00:00:00 2001 From: sepehr Date: Sun, 31 May 2026 21:59:18 +0200 Subject: [PATCH] fix: safe JSON parse in checkout handlers, show proper error on 500 --- frontend/src/app/pricing/page.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/frontend/src/app/pricing/page.tsx b/frontend/src/app/pricing/page.tsx index bd9df16..fedcc6e 100644 --- a/frontend/src/app/pricing/page.tsx +++ b/frontend/src/app/pricing/page.tsx @@ -378,12 +378,16 @@ export default function PricingPage() { billing_period: isYearly ? "yearly" : "monthly", }), }); - const data = await res.json(); + + // Safe JSON parse — backend may return plain text on 500 + let data: any = {}; + try { data = await res.json(); } catch { /* ignore */ } + const url = data.data?.url ?? data.url; const backendMessage = data.message ?? data.error ?? data.data?.error; if (!res.ok) { - throw new Error(backendMessage || t('pricing.toast.paymentError')); + throw new Error(backendMessage || `Erreur serveur ${res.status}`); } if (url) { @@ -420,10 +424,14 @@ export default function PricingPage() { }, body: JSON.stringify({ package_index: packageIndex }), }); - const data = await res.json(); + + // Safe JSON parse + let data: any = {}; + try { data = await res.json(); } catch { /* ignore */ } + const url = data.data?.url ?? data.url; if (!res.ok) { - throw new Error(data.message ?? data.error ?? t('pricing.toast.paymentError')); + throw new Error(data.message ?? data.error ?? `Erreur serveur ${res.status}`); } if (url) { window.location.replace(url);