From d6dae6825c9c04327dda4c5248e355b0979024eb Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Thu, 8 Jan 2026 12:50:11 -0500 Subject: [PATCH] read response.txt once --- assets/js/ticket.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/assets/js/ticket.js b/assets/js/ticket.js index 6b21167..b0f014d 100644 --- a/assets/js/ticket.js +++ b/assets/js/ticket.js @@ -402,20 +402,25 @@ function updateTicketStatus() { status: newStatus }) }) - .then(response => { + .then(async response => { + const text = await response.text(); + if (!response.ok) { - return response.json().then(data => { - console.error('Server error response:', data); + console.error('Server error response:', text); + try { + const data = JSON.parse(text); throw new Error(data.error || 'Server returned an error'); - }).catch(jsonError => { - // If JSON parsing fails, try to get text - return response.text().then(text => { - console.error('Server response (non-JSON):', text); - throw new Error(text || 'Network response was not ok'); - }); - }); + } catch (parseError) { + throw new Error(text || 'Network response was not ok'); + } + } + + try { + return JSON.parse(text); + } catch (parseError) { + console.error('Failed to parse JSON:', text); + throw new Error('Invalid JSON response from server'); } - return response.json(); }) .then(data => { if (data.success) {