fix: safe JSON parse in checkout handlers, show proper error on 500
Some checks failed
Deploy to Production / Build and Deploy (push) Failing after 1m32s
Some checks failed
Deploy to Production / Build and Deploy (push) Failing after 1m32s
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user