fix: updateBedtimeRange variable scoping - originalText accessible in finally block

This commit is contained in:
2026-02-28 23:26:02 +02:00
parent 7bcb670b96
commit d3fb0eacb6

View File

@@ -2544,12 +2544,15 @@ async function updateBedtimeRange(guildId) {
const [startHour, startMinute] = startTime.split(':').map(Number);
const [endHour, endMinute] = endTime.split(':').map(Number);
const button = document.querySelector(`button[onclick="updateBedtimeRange('${guildIdStr}')"]`);
const originalText = button ? button.textContent : 'Update Bedtime Range';
try {
// Show loading state
const button = document.querySelector(`button[onclick="updateBedtimeRange('${guildIdStr}')"]`);
const originalText = button.textContent;
button.textContent = 'Updating...';
button.disabled = true;
if (button) {
button.textContent = 'Updating...';
button.disabled = true;
}
// Send the update request
const response = await fetch(`/servers/${guildIdStr}/bedtime-range`, {
@@ -2579,9 +2582,8 @@ async function updateBedtimeRange(guildId) {
} catch (error) {
console.error('Failed to update bedtime range:', error);
showNotification(error.message || 'Failed to update bedtime range', 'error');
} finally {
// Restore button state
const button = document.querySelector(`button[onclick="updateBedtimeRange('${guildIdStr}')"]`);
if (button) {
button.textContent = originalText;
button.disabled = false;