diff --git a/server/index.js b/server/index.js index 5747e95d..dae9575d 100644 --- a/server/index.js +++ b/server/index.js @@ -111,6 +111,10 @@ CRITICAL: content_svg MUST be a string with single quotes in SVG attributes. Pat const jsonStr = text.replace(/```json/g, '').replace(/```/g, '').trim(); const data = JSON.parse(jsonStr); + if (!data.title || !data.sections || !Array.isArray(data.sections)) { + throw new Error('Invalid generation format'); + } + res.json(data); } catch (error) { console.error('Generation error:', error); diff --git a/src/App.jsx b/src/App.jsx index 3e114cd4..64db2b45 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -11,9 +11,11 @@ function App() { const [isGenerating, setIsGenerating] = React.useState(false); const [history, setHistory] = React.useState([]); + const [error, setError] = React.useState(null); const handleGenerate = async (data) => { setIsGenerating(true); + setError(null); try { const response = await fetch('/api/generate', { method: 'POST', @@ -40,7 +42,7 @@ function App() { } catch (error) { console.error("Error generating sheet:", error); - // Optional: Show error state + setError(error.message || "Failed to generate sheet. Please try again."); } finally { setIsGenerating(false); } @@ -75,6 +77,11 @@ function App() { {/* Main Content */}
+ {error && ( +
+ Error: {error} +
+ )}
diff --git a/src/components/Hero.jsx b/src/components/Hero.jsx index 777ca05e..a9894a13 100644 --- a/src/components/Hero.jsx +++ b/src/components/Hero.jsx @@ -68,7 +68,7 @@ export const Hero = ({ onGenerate, generatedSheet, isGenerating }) => { // since we don't have a separate loading state, we can reuse isGenerating logic or add one. // For now, we'll just set the values when they arrive. - const res = await fetch('http://localhost:3001/api/surprise', { method: 'POST' }); + const res = await fetch('/api/surprise', { method: 'POST' }); if (!res.ok) throw new Error('Surprise failed'); const idea = await res.json(); @@ -310,7 +310,7 @@ export const Hero = ({ onGenerate, generatedSheet, isGenerating }) => { >
{sec.type}
{/* Handle both new content_svg and legacy content fields */} - {(sec.content_svg || sec.content || '').trim().startsWith('