Improve error handling in workflow creation and data loading

- Separated JSON validation from API call error handling
- Changed refreshData() to async with individual try-catch blocks
- Better error messages: "Invalid JSON" vs "Error creating workflow"
- Console.error logging for each data loading function
- Changed success alert to terminal notification
- This will help identify which specific function is failing

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-07 23:27:54 -05:00
parent 2f941d0b6f
commit f8b8427f77

View File

@@ -2169,25 +2169,31 @@
return; return;
} }
let definition;
try {
definition = JSON.parse(definitionText);
} catch (error) {
alert('Invalid JSON definition: ' + error.message);
return;
}
try { try {
const definition = JSON.parse(definitionText);
const response = await fetch('/api/workflows', { const response = await fetch('/api/workflows', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name, description, definition }) body: JSON.stringify({ name, description, definition })
}); });
if (response.ok) { if (response.ok) {
alert('Workflow created!');
closeModal('createWorkflowModal'); closeModal('createWorkflowModal');
switchTab('workflows'); switchTab('workflows');
showTerminalNotification('Workflow created successfully!', 'success');
refreshData(); refreshData();
} else { } else {
alert('Failed to create workflow'); alert('Failed to create workflow');
} }
} catch (error) { } catch (error) {
alert('Invalid JSON definition: ' + error.message); alert('Error creating workflow: ' + error.message);
} }
} }
@@ -2350,11 +2356,30 @@
document.getElementById(tabName).classList.add('active'); document.getElementById(tabName).classList.add('active');
} }
function refreshData() { async function refreshData() {
loadWorkers(); try {
loadWorkflows(); await loadWorkers();
loadExecutions(); } catch (e) {
loadSchedules(); console.error('Error loading workers:', e);
}
try {
await loadWorkflows();
} catch (e) {
console.error('Error loading workflows:', e);
}
try {
await loadExecutions();
} catch (e) {
console.error('Error loading executions:', e);
}
try {
await loadSchedules();
} catch (e) {
console.error('Error loading schedules:', e);
}
} }
// Terminal beep sound (Web Audio API) // Terminal beep sound (Web Audio API)