AI Image Editor error handling
Two things happen when a generation or edit fails. The editor handles the
user: it shows a
localized message in place
and stays usable, with no wiring needed on your side. Your app gets the
uc:error event for everything the built-in UI can’t know about: logging,
metrics, or reacting to specific failures.
The event bubbles and crosses shadow DOM boundaries (composed), so a
listener on a container, or on document, works too.
The error object
detail.error is always an AiImageEditorError. Whatever actually went
wrong (a platform rejection, a network failure, even a custom provider
throwing a string) is normalized into it:
Error codes
code is the field to branch on:
The known codes come in three families. Platform validation covers bad
input or setup (invalid_source, canvas_too_large, derivative_disabled,
and so on). AI gateway covers the generation itself
(content_moderated, provider_unavailable, generation_timeout).
Upload pipeline covers persisting the result
(DownloadFileHTTPClientError and friends; yes, PascalCase, because the
backend passes those through as literal upload-service class names). The full
list with their user-facing messages lives in the
localization guide.
AiImageEditorErrorCode is deliberately open: the known codes are typed as
literals (you get autocomplete for them), but the backend can introduce new
ones at any time, so any other string flows through rather than breaking.
Don’t treat the union as closed; keep a default branch.
Enabling AI Image Editor
derivative_disabled means AI generation isn’t enabled for your project.
During the public beta, AI Image Editor is available on all paid
Uploadcare plans. Upgrade your plan if
you’re on a free one, or contact support if you hit this code on a paid
account.
React
The React wrapper delivers the same object to
onError:
One React-specific case: if the lazily-loaded editor engine itself fails to
load (e.g. a chunk request dies on a flaky connection), onError receives an
AiImageEditorError with code: 'engine_load_failed' and the fallback stays
rendered. That code is frontend-originated, so it never appears in the backend
families above.
Customizing the in-editor messages
The message the editor shows for a code is a locale string, overridable per-code without touching your event handling:
A code with no matching key (unknown or untranslated) falls back to the
generic ai-image-editor-error message. See
Localization for the
mechanics and the full key list.
Server-side code
instanceof AiImageEditorError works in server code too. Import the class from
the side-effect-free errors entry, which is safe where the main entry is not
(the main entry registers custom elements):
What doesn’t fire uc:error
- Cancellations. Closing the editor fires
uc:cancel; superseding or aborting an in-flight generation (Start over, unmount) is swallowed silently, since an abort is a user action rather than a failure. - Image display failures. If a result generated fine but its image fails
to load into the canvas, that surfaces as a separate
uc:image-errorevent (detail.urlnames the failing URL). The generation itself didn’t fail.