fix(dashboard): surface server error messages in create-stack flow

- Read JSON error body from non-ok responses before throwing, so
  status-specific messages (409 already exists, 400 invalid name) reach
  the user instead of generic hardcoded strings
- Apply defensive toast pattern: error?.message || error?.error || fallback
This commit is contained in:
SaelixCode
2026-03-20 09:57:01 -04:00
parent 18314119b0
commit 3b2634f9dd
2 changed files with 11 additions and 4 deletions
+10 -4
View File
@@ -174,23 +174,29 @@ export default function HomeDashboard() {
method: 'POST',
body: JSON.stringify({ stackName }),
});
if (!createResponse.ok) throw new Error('Failed to create stack');
if (!createResponse.ok) {
const err = await createResponse.json().catch(() => ({}));
throw new Error(err.error || 'Failed to create stack');
}
// Save the converted YAML content
const saveResponse = await apiFetch(`/stacks/${stackName}`, {
method: 'PUT',
body: JSON.stringify({ content: convertedYaml }),
});
if (!saveResponse.ok) throw new Error('Failed to save stack content');
if (!saveResponse.ok) {
const err = await saveResponse.json().catch(() => ({}));
throw new Error(err.error || 'Failed to save stack content');
}
setCreateDialogOpen(false);
setNewStackName('');
setConvertedYaml('');
setDockerRunInput('');
window.location.reload(); // Refresh to show new stack
} catch (error) {
} catch (error: any) {
console.error('Failed to create stack:', error);
toast.error('Failed to create stack');
toast.error(error?.message || error?.error || 'Failed to create stack');
}
};