From 3ae39830e209812af75600fa9460cea593cbd97b Mon Sep 17 00:00:00 2001 From: Purple Date: Sun, 18 Jan 2026 13:48:56 +0000 Subject: [PATCH] Fix WebDAV backup error handling and license_info table queries - Wrap license_info queries in try-catch for backup export functions - Add detailed error messages to WebDAV backup responses (URL, HTTP code) - Include WebDAV response body in error messages for debugging - Update JS to display detailed error info in the UI Co-Authored-By: Claude Opus 4.5 --- webapp/api.php | 30 +++++++++++++++++++++++++----- webapp/settings.php | 12 ++++++++++-- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/webapp/api.php b/webapp/api.php index 5c2effd..cdf0d82 100644 --- a/webapp/api.php +++ b/webapp/api.php @@ -3770,9 +3770,14 @@ function handleBackupExport($db) { $stmt = $db->query("SELECT id, email, role, display_name, active, created_at FROM admin_users ORDER BY id"); $backup['users'] = $stmt->fetchAll(PDO::FETCH_ASSOC); - // Export license info - $stmt = $db->query("SELECT * FROM license_info WHERE is_active = 1 ORDER BY id DESC LIMIT 1"); - $backup['license'] = $stmt->fetch(PDO::FETCH_ASSOC); + // Export license info (if table exists) + try { + $stmt = $db->query("SELECT * FROM license_info WHERE is_active = 1 ORDER BY id DESC LIMIT 1"); + $backup['license'] = $stmt->fetch(PDO::FETCH_ASSOC); + } catch (Exception $e) { + // Table may not exist yet + $backup['license'] = null; + } jsonResponse([ 'success' => true, @@ -3973,6 +3978,15 @@ function handleWebDAVBackup($db) { $stmt = $db->query("SELECT id, email, role, display_name, active, created_at FROM admin_users ORDER BY id"); $backup['users'] = $stmt->fetchAll(PDO::FETCH_ASSOC); + // Export license info (if table exists) + try { + $stmt = $db->query("SELECT * FROM license_info WHERE is_active = 1 ORDER BY id DESC LIMIT 1"); + $backup['license'] = $stmt->fetch(PDO::FETCH_ASSOC); + } catch (Exception $e) { + // Table may not exist yet + $backup['license'] = null; + } + $jsonData = json_encode($backup, JSON_PRETTY_PRINT); // Generate filename with timestamp @@ -4018,10 +4032,16 @@ function handleWebDAVBackup($db) { jsonResponse([ 'success' => true, 'message' => 'Backup uploaded successfully', - 'filename' => $filename + 'filename' => $filename, + 'url' => $webdavUrl ]); } else { - jsonResponse(['error' => "WebDAV upload failed with HTTP $httpCode"], 500); + // Include response body for debugging + $errorMsg = "WebDAV upload failed with HTTP $httpCode"; + if (!empty($response)) { + $errorMsg .= ": " . substr($response, 0, 200); + } + jsonResponse(['error' => $errorMsg, 'url' => $webdavUrl, 'http_code' => $httpCode], 500); } } catch (Exception $e) { diff --git a/webapp/settings.php b/webapp/settings.php index e308aff..31478b6 100644 --- a/webapp/settings.php +++ b/webapp/settings.php @@ -1616,14 +1616,22 @@ async function backupToWebDAV() { } if (!data.success) { - throw new Error(data.error || "WebDAV backup failed"); + // Include extra details if available + let errorMsg = data.error || "WebDAV backup failed"; + if (data.url) { + errorMsg += ` (URL: ${data.url})`; + } + if (data.http_code) { + errorMsg += ` (HTTP: ${data.http_code})`; + } + throw new Error(errorMsg); } statusDiv.innerHTML = `
Backup uploaded successfully!
Filename: ${escapeHtml(data.filename)}
`; showNotification("Backup uploaded to WebDAV", "success"); } catch (error) { console.error("WebDAV backup error:", error); - statusDiv.innerHTML = `
WebDAV backup failed: ${escapeHtml(error.message)}
`; + statusDiv.innerHTML = `
WebDAV backup failed: ${escapeHtml(error.message)}
`; } }