read response.txt once
This commit is contained in:
@@ -402,20 +402,25 @@ function updateTicketStatus() {
|
|||||||
status: newStatus
|
status: newStatus
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(async response => {
|
||||||
|
const text = await response.text();
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
return response.json().then(data => {
|
console.error('Server error response:', text);
|
||||||
console.error('Server error response:', data);
|
try {
|
||||||
|
const data = JSON.parse(text);
|
||||||
throw new Error(data.error || 'Server returned an error');
|
throw new Error(data.error || 'Server returned an error');
|
||||||
}).catch(jsonError => {
|
} catch (parseError) {
|
||||||
// If JSON parsing fails, try to get text
|
throw new Error(text || 'Network response was not ok');
|
||||||
return response.text().then(text => {
|
}
|
||||||
console.error('Server response (non-JSON):', text);
|
}
|
||||||
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 => {
|
.then(data => {
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
|
|||||||
Reference in New Issue
Block a user