Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions ui/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ document.addEventListener('DOMContentLoaded', async function () {
}

// --- Utility Functions ---
function formatErrorDetail(detail) {
if (typeof detail === 'string') return detail;
if (Array.isArray(detail)) return detail.map(e => e.msg || JSON.stringify(e)).join('; ');
if (detail && typeof detail === 'object') return JSON.stringify(detail);
return String(detail);
}

function showNotification(message, type = 'info', duration = 5000) {
if (!notificationArea) return null;

Expand Down Expand Up @@ -270,7 +277,7 @@ document.addEventListener('DOMContentLoaded', async function () {
});
if (!response.ok) {
const errorResult = await response.json();
throw new Error(errorResult.detail || `Failed to save UI state (status ${response.status})`);
throw new Error(formatErrorDetail(errorResult.detail) || `Failed to save UI state (status ${response.status})`);
}
} catch (error) {
console.error("Error saving UI state via API:", error);
Expand Down Expand Up @@ -526,7 +533,7 @@ document.addEventListener('DOMContentLoaded', async function () {

if (!response.ok) {
const errorResult = await response.json().catch(() => ({ detail: 'Failed to save' }));
throw new Error(errorResult.detail || 'Failed to save model configuration');
throw new Error(formatErrorDetail(errorResult.detail) || 'Failed to save model configuration');
}

showNotification('Model configuration saved. Initiating server restart...', 'info');
Expand Down Expand Up @@ -1085,7 +1092,7 @@ document.addEventListener('DOMContentLoaded', async function () {
});
if (!response.ok) {
const errorResult = await response.json().catch(() => ({ detail: `HTTP error ${response.status}` }));
throw new Error(errorResult.detail || 'TTS generation failed.');
throw new Error(formatErrorDetail(errorResult.detail) || 'TTS generation failed.');
}
const audioBlob = await response.blob();
const endTime = performance.now();
Expand Down Expand Up @@ -1331,7 +1338,7 @@ document.addEventListener('DOMContentLoaded', async function () {
});
if (!response.ok) {
const errorResult = await response.json().catch(() => ({ detail: 'Failed to reset settings on server.' }));
throw new Error(errorResult.detail);
throw new Error(formatErrorDetail(errorResult.detail));
}
const result = await response.json();
updateConfigStatus(resetSettingsBtn, configStatus, result.message + " Reloading page...", 'success', 0, false);
Expand Down