Canvix — Free & open-source graphic design tool. A community-built Canva alternative with a drag-and-drop editor, templates, shapes, text, images & one-click export. Works on desktop, tablet & mobile.
TypeScript canva-alternativecanvasdesigndesign-tooldrag-and-dropeditorgraphic-designkonvanextjsopen-sourcereactself-hostedtemplatestypescript
feat(ui): image AI failures surface the provider's reason (#43)
Ashiq Hussain Mir07acba393607
diff --git a/src/components/editor/ImageAI.tsx b/src/components/editor/ImageAI.tsxindex e33aaef..c95ff1a 100644--- a/src/components/editor/ImageAI.tsx+++ b/src/components/editor/ImageAI.tsx@@ -14,6 +14,24 @@ interface EditResponse {width?: numberheight?: numbererror?: string+ /** scrubbed provider reason (502 PROVIDER_ERROR bodies) — shown to the user */+ detail?: string+}++/** Pull a human reason out of a provider `detail` string. The API layer+ * scrubs and forwards the provider's raw error text; when it is JSON+ * (OpenAI-style {"error":{"message":...}}) extract the message, else+ * pass the text through. Always capped for toast display. */+function providerReason(detail?: string): string {+ if (!detail) return ''+ try {+ const parsed = JSON.parse(detail.replace(/ \(HTTP \d+\)$/, ''))+ const msg = parsed?.error?.message+ if (typeof msg === 'string' && msg) return msg+ } catch {+ /* not JSON — use as-is */+ }+ return detail}/** Normalise an element src into something the AI service can consume:@@ -52,7 +70,8 @@ async function runImageAI(})const data = (await res.json()) as EditResponseif (!res.ok || !data.dataUrl) {- onDone(data.error ?? 'The edit failed. Please try again.')+ const reason = providerReason(data.detail)+ onDone(reason ? `${data.error ?? 'The edit failed.'} — ${reason.slice(0, 220)}` : (data.error ?? 'The edit failed. Please try again.'))return false}const w = data.width || el.naturalWidth