mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 03:01:54 +00:00
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
This commit is contained in:
@@ -223,10 +223,23 @@ const initiateCheckout = async (tierKey: TierKey) => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!response.ok) {
|
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(
|
throw new FirebaseAuthStoreError(
|
||||||
t('toastMessages.failedToInitiateSubscription', {
|
t('toastMessages.failedToInitiateSubscription', {
|
||||||
error: errorData.message || 'Failed to initiate checkout'
|
error: errorMessage
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user