read response.txt once

This commit is contained in:
2026-01-08 12:50:11 -05:00
parent d76ff7aad0
commit d6dae6825c

View File

@@ -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) {