Refactor source status fetching logic for improved error handling
Some checks failed
CI / ci (push) Has been cancelled
Some checks failed
CI / ci (push) Has been cancelled
- Enhanced the JavaScript fetch logic in base.html to better handle API responses, including improved error messaging and structured data handling. - Updated the way source status is processed, ensuring clearer differentiation between successful and error states for Prometheus and OpenStack metrics.
This commit is contained in:
@@ -107,10 +107,24 @@
|
||||
var promEl = document.getElementById('source-status-prometheus');
|
||||
var osEl = document.getElementById('source-status-openstack');
|
||||
if (!promEl || !osEl) return;
|
||||
fetch('/api/source-status/').then(function(r) { return r.ok ? r.json() : {}; }).then(function(data) {
|
||||
updateSourceStatus(promEl, 'Prometheus', data.prometheus);
|
||||
updateSourceStatus(osEl, 'OpenStack', data.openstack);
|
||||
}).catch(function() {
|
||||
fetch('/api/source-status/')
|
||||
.then(function(r) {
|
||||
if (r.ok) return r.json().then(function(data) { return { data: data }; });
|
||||
return r.json().catch(function() { return {}; }).then(function(body) {
|
||||
return { error: true, message: (body && body.message) || 'Failed to fetch status' };
|
||||
});
|
||||
})
|
||||
.then(function(result) {
|
||||
if (result && result.error) {
|
||||
updateSourceStatus(promEl, 'Prometheus', { status: 'error', message: result.message });
|
||||
updateSourceStatus(osEl, 'OpenStack', { status: 'error', message: result.message });
|
||||
} else {
|
||||
var data = result && result.data;
|
||||
updateSourceStatus(promEl, 'Prometheus', data && data.prometheus);
|
||||
updateSourceStatus(osEl, 'OpenStack', data && data.openstack);
|
||||
}
|
||||
})
|
||||
.catch(function() {
|
||||
updateSourceStatus(promEl, 'Prometheus', { status: 'error', message: 'Failed to fetch status' });
|
||||
updateSourceStatus(osEl, 'OpenStack', { status: 'error', message: 'Failed to fetch status' });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user