From 8b7194e0733d95dec85c8eab7599c411d879b24a Mon Sep 17 00:00:00 2001 From: bymyself Date: Thu, 11 Dec 2025 00:57:29 -0800 Subject: [PATCH] fix: improve error handling for non-JSON API responses - Wrap response.json() in try-catch to handle non-JSON responses - Fall back to response.text() and HTTP status information - Preserve original HTTP error details instead of masking with JSON parse errors - Ensure robust error reporting for HTML/text responses from server --- .../subscription/components/PricingTable.vue | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/platform/cloud/subscription/components/PricingTable.vue b/src/platform/cloud/subscription/components/PricingTable.vue index 404f3b0ed..f8aa3eb6d 100644 --- a/src/platform/cloud/subscription/components/PricingTable.vue +++ b/src/platform/cloud/subscription/components/PricingTable.vue @@ -223,10 +223,23 @@ const initiateCheckout = async (tierKey: TierKey) => { ) if (!response.ok) { - const errorData = await response.json() + let errorMessage = 'Failed to initiate checkout' + try { + const errorData = await response.json() + errorMessage = errorData.message || errorMessage + } catch { + // If JSON parsing fails, try to get text response or use HTTP status + try { + const errorText = await response.text() + errorMessage = errorText || `HTTP ${response.status} ${response.statusText}` + } catch { + errorMessage = `HTTP ${response.status} ${response.statusText}` + } + } + throw new FirebaseAuthStoreError( t('toastMessages.failedToInitiateSubscription', { - error: errorData.message || 'Failed to initiate checkout' + error: errorMessage }) ) }