Compare commits

...

1 Commits
main ... dev

Author SHA1 Message Date
Jeff Emmett 3a02c84b94 fix: handle non-JSON error responses in design pipeline
Frontend was crashing with "Unexpected token 'I'" when the backend
returned plain text errors (e.g. "Internal Server Error" from proxy).
Now safely falls back to response.text() when JSON parsing fails.
Also prevents backend from swallowing HTTPException in catch-all.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 17:16:31 -08:00
3 changed files with 56 additions and 12 deletions

View File

@ -126,6 +126,8 @@ Square format, clean edges for die-cut sticker."""
status_code=504, status_code=504,
detail="AI generation timed out" detail="AI generation timed out"
) )
except HTTPException:
raise
except Exception as e: except Exception as e:
raise HTTPException( raise HTTPException(
status_code=502, status_code=502,

View File

@ -54,8 +54,15 @@ export default function DesignPage() {
}); });
if (!response.ok) { if (!response.ok) {
const data = await response.json(); let message = "Failed to generate design";
throw new Error(data.detail || "Failed to generate design"); try {
const data = await response.json();
message = data.detail || message;
} catch {
const text = await response.text();
message = text || `Server error (${response.status})`;
}
throw new Error(message);
} }
const design = await response.json(); const design = await response.json();
@ -82,8 +89,15 @@ export default function DesignPage() {
); );
if (!response.ok) { if (!response.ok) {
const data = await response.json(); let message = "Failed to activate design";
throw new Error(data.detail || "Failed to activate design"); try {
const data = await response.json();
message = data.detail || message;
} catch {
const text = await response.text();
message = text || `Server error (${response.status})`;
}
throw new Error(message);
} }
setGeneratedDesign({ ...generatedDesign, status: "active" }); setGeneratedDesign({ ...generatedDesign, status: "active" });
@ -106,8 +120,15 @@ export default function DesignPage() {
); );
if (!response.ok) { if (!response.ok) {
const data = await response.json(); let message = "Failed to delete design";
throw new Error(data.detail || "Failed to delete design"); try {
const data = await response.json();
message = data.detail || message;
} catch {
const text = await response.text();
message = text || `Server error (${response.status})`;
}
throw new Error(message);
} }
setGeneratedDesign(null); setGeneratedDesign(null);

View File

@ -103,8 +103,15 @@ export default function UploadPage() {
}); });
if (!response.ok) { if (!response.ok) {
const data = await response.json(); let message = "Upload failed";
throw new Error(data.detail || "Upload failed"); try {
const data = await response.json();
message = data.detail || message;
} catch {
const text = await response.text();
message = text || `Server error (${response.status})`;
}
throw new Error(message);
} }
const design = await response.json(); const design = await response.json();
@ -127,8 +134,15 @@ export default function UploadPage() {
{ method: "POST" } { method: "POST" }
); );
if (!response.ok) { if (!response.ok) {
const data = await response.json(); let message = "Failed to activate design";
throw new Error(data.detail || "Failed to activate design"); try {
const data = await response.json();
message = data.detail || message;
} catch {
const text = await response.text();
message = text || `Server error (${response.status})`;
}
throw new Error(message);
} }
setUploadedDesign({ ...uploadedDesign, status: "active" }); setUploadedDesign({ ...uploadedDesign, status: "active" });
} catch (err) { } catch (err) {
@ -146,8 +160,15 @@ export default function UploadPage() {
{ method: "DELETE" } { method: "DELETE" }
); );
if (!response.ok) { if (!response.ok) {
const data = await response.json(); let message = "Failed to delete design";
throw new Error(data.detail || "Failed to delete design"); try {
const data = await response.json();
message = data.detail || message;
} catch {
const text = await response.text();
message = text || `Server error (${response.status})`;
}
throw new Error(message);
} }
resetForm(); resetForm();
} catch (err) { } catch (err) {