read response.txt once
This commit is contained in:
@@ -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);
|
||||
} catch (parseError) {
|
||||
throw new Error(text || 'Network response was not ok');
|
||||
});
|
||||
});
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
try {
|
||||
return JSON.parse(text);
|
||||
} catch (parseError) {
|
||||
console.error('Failed to parse JSON:', text);
|
||||
throw new Error('Invalid JSON response from server');
|
||||
}
|
||||
})
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
|
||||
Reference in New Issue
Block a user