Fix: Add missing printing module table and improve database management error handling

- Added order_for_labels table to init_db.py (printing/labels module)
- Fixed fetch API calls in database management to properly check HTTP response status before parsing JSON
- Prevents 'Unexpected token' errors when server returns HTML error pages instead of JSON
- Improved error messages for better debugging (shows HTTP status codes)
- All 10 database management API endpoints now have proper error handling
This commit is contained in:
Quality App Developer
2026-02-15 20:54:32 +02:00
parent e2a6553fe9
commit fd6db40339
2 changed files with 75 additions and 15 deletions

View File

@@ -477,7 +477,10 @@ document.addEventListener('DOMContentLoaded', function() {
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(response => {
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
return response.json();
})
.then(data => {
if (data.success) {
alert('Cleanup completed! ' + (data.deleted_count || 0) + ' old backups deleted.');
@@ -512,7 +515,10 @@ document.addEventListener('DOMContentLoaded', function() {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(response => {
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
return response.json();
})
.then(data => {
if (data.success) {
alert('Backup created successfully: ' + data.file);
@@ -677,7 +683,15 @@ document.addEventListener('DOMContentLoaded', function() {
},
body: JSON.stringify({ table: table })
})
.then(response => response.json())
.then(response => {
if (!response.ok) {
if (response.status === 401) {
throw new Error('Unauthorized. Please log in again.');
}
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(data => {
if (data.success) {
// Hide modal
@@ -701,16 +715,16 @@ document.addEventListener('DOMContentLoaded', function() {
} else {
alert('Error: ' + data.error);
// Re-enable button
this.disabled = false;
this.innerHTML = '<i class="fas fa-trash"></i> Yes, Clear All Data';
confirmBtn.disabled = false;
confirmBtn.innerHTML = '<i class="fas fa-trash"></i> Yes, Clear All Data';
}
})
.catch(error => {
console.error('Error:', error);
alert('Error clearing table: ' + error);
alert('Error clearing table: ' + error.message);
// Re-enable button
this.disabled = false;
this.innerHTML = '<i class="fas fa-trash"></i> Yes, Clear All Data';
confirmBtn.disabled = false;
confirmBtn.innerHTML = '<i class="fas fa-trash"></i> Yes, Clear All Data';
});
});
}
@@ -739,7 +753,10 @@ document.addEventListener('DOMContentLoaded', function() {
},
body: JSON.stringify({ backup: backup })
})
.then(response => response.json())
.then(response => {
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
return response.json();
})
.then(data => {
if (data.success) {
alert('Database restored successfully!');
@@ -758,7 +775,10 @@ document.addEventListener('DOMContentLoaded', function() {
function loadBackupsList() {
fetch('{{ url_for("settings.get_backups_list") }}')
.then(response => response.json())
.then(response => {
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
return response.json();
})
.then(data => {
if (data.backups && data.backups.length > 0) {
const tbody = document.getElementById('backups-list');
@@ -837,7 +857,10 @@ function toggleDayOfWeek() {
function loadBackupSchedules() {
fetch('{{ url_for("settings.get_backup_schedules") }}')
.then(response => response.json())
.then(response => {
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
return response.json();
})
.then(data => {
const tbody = document.getElementById('schedules-list');
@@ -925,7 +948,10 @@ function saveBackupSchedule() {
},
body: JSON.stringify(payload)
})
.then(response => response.json())
.then(response => {
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
return response.json();
})
.then(data => {
if (data.success) {
alert('Backup schedule created successfully!');
@@ -949,7 +975,10 @@ function deleteSchedule(scheduleId) {
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(response => {
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
return response.json();
})
.then(data => {
if (data.success) {
alert('Schedule deleted successfully!');
@@ -972,7 +1001,10 @@ function toggleSchedule(scheduleId) {
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(response => {
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
return response.json();
})
.then(data => {
if (data.success) {
loadBackupSchedules();
@@ -1010,7 +1042,10 @@ function uploadBackupFile() {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(response => {
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
return response.json();
})
.then(data => {
if (data.success) {
statusDiv.innerHTML = '<div class="alert alert-success"><i class="fas fa-check-circle"></i> File uploaded successfully: ' + data.filename + ' (' + data.size + ' bytes)</div>';