Update static/js/pages/visual-route.js
This commit is contained in:
parent
0aad5c3fd3
commit
12be020717
1 changed files with 12 additions and 10 deletions
|
|
@ -41,26 +41,28 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
body: JSON.stringify({ ip_address: ipAddress })
|
body: JSON.stringify({ ip_address: ipAddress })
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
return response.json().then(data => {
|
||||||
|
if (!response.ok && data.error) {
|
||||||
|
throw new Error(data.error);
|
||||||
|
}
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
}
|
}
|
||||||
return response.json();
|
return data;
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
loader.style.display = 'none';
|
loader.style.display = 'none';
|
||||||
if (data.error) {
|
if (data.nodes && data.nodes.length > 0) {
|
||||||
errorMessageContainer.textContent = data.error;
|
|
||||||
errorMessageContainer.style.display = 'block';
|
|
||||||
} else if (data.nodes && data.nodes.length > 0) {
|
|
||||||
drawGraph(data);
|
drawGraph(data);
|
||||||
} else {
|
} else {
|
||||||
errorMessageContainer.textContent = 'Could not parse any valid AS paths from the API response.';
|
errorMessageContainer.textContent = data.error || 'Could not parse any valid AS paths from the API response.';
|
||||||
errorMessageContainer.style.display = 'block';
|
errorMessageContainer.style.display = 'block';
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
loader.style.display = 'none';
|
loader.style.display = 'none';
|
||||||
errorMessageContainer.textContent = 'An unexpected error occurred. See console for details.';
|
errorMessageContainer.textContent = error.message;
|
||||||
errorMessageContainer.style.display = 'block';
|
errorMessageContainer.style.display = 'block';
|
||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue