remove last message if 429

This commit is contained in:
Raven Scott 2024-10-02 15:31:33 -04:00
parent 49b94d9e13
commit f1b9abb4e0

View File

@ -157,10 +157,21 @@ function displayAlert(type, message) {
// Handles error responses based on status code // Handles error responses based on status code
function handleErrorResponse(status) { function handleErrorResponse(status) {
const messages = document.getElementById('messages');
const lastMessage = messages.lastElementChild;
if (status === 429) { if (status === 429) {
displayAlert('error', 'Sorry, I am currently too busy at the moment!'); displayAlert('error', 'Sorry, I am currently too busy at the moment!');
// Remove the last user message if the status is 429
if (lastMessage && lastMessage.classList.contains('user')) {
messages.removeChild(lastMessage);
}
} else { } else {
displayMessage('Error: ' + status, 'assistant'); displayMessage('Error: ' + status, 'assistant');
// Remove the last user message for any other errors
if (lastMessage && lastMessage.classList.contains('user')) {
messages.removeChild(lastMessage);
}
} }
} }