Improve error handling in import progress fetch
Enhances the fetch logic to detect and handle non-JSON server responses, providing clearer error messages for PHP errors or session issues. Also adds specific handling for gateway timeouts by retrying the request after 5 seconds.
This commit is contained in:
@@ -223,7 +223,19 @@ function checkProgress() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fetch(`/tld-registry/api/import-progress?log_id=${logId}`)
|
fetch(`/tld-registry/api/import-progress?log_id=${logId}`)
|
||||||
.then(response => response.json())
|
.then(response => {
|
||||||
|
// Check if response is actually JSON
|
||||||
|
const contentType = response.headers.get('content-type');
|
||||||
|
if (!contentType || !contentType.includes('application/json')) {
|
||||||
|
return response.text().then(text => {
|
||||||
|
addLogMessage('Server returned non-JSON response. This might be a PHP error or session issue.', 'error');
|
||||||
|
addLogMessage('Response preview: ' + text.substring(0, 200) + '...', 'error');
|
||||||
|
isComplete = true;
|
||||||
|
throw new Error('Non-JSON response received');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (data.error) {
|
if (data.error) {
|
||||||
addLogMessage('Error: ' + data.error, 'error');
|
addLogMessage('Error: ' + data.error, 'error');
|
||||||
@@ -238,8 +250,13 @@ function checkProgress() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
addLogMessage('Network error: ' + error.message, 'error');
|
if (error.message.includes('Gateway Timeout') || error.message.includes('timeout')) {
|
||||||
isComplete = true;
|
addLogMessage('Gateway timeout detected. Retrying in 5 seconds...', 'warning');
|
||||||
|
setTimeout(checkProgress, 5000); // Retry after 5 seconds
|
||||||
|
} else {
|
||||||
|
addLogMessage('Network error: ' + error.message, 'error');
|
||||||
|
isComplete = true;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user