Error
A turn that failed, shown inside that turn — one plain sentence in the reader's language, chosen by the error's code, the technical message on the console — with whatever had already arrived kept above it.
-
type: 'error'
<aparte-chat-bubble message-id="u1" data-role="user" content="Summarise the release notes."></aparte-chat-bubble>
<aparte-chat-bubble message-id="a1" data-role="assistant"></aparte-chat-bubble>
<script>
// The failure sits in the turn that produced it, not in a toast elsewhere on the page.
// As the client makes it: the code picks the sentence the reader sees; the provider's own
// message stays on the segment, and went to the console.
document.querySelectorAll('aparte-chat-bubble')[1].setSegments([{
id: 's1',
type: 'error',
code: 'USAGE_RATE_LIMIT',
content: 'HTTP 429: {"error":{"type":"rate_limit_error","message":"Number of requests exceeded"}}',
}]);
</script>When a turn fails (the provider rejects the request, the network drops, a limit is reached), the
failure is an error segment in the reply that failed, not a toast somewhere else on the page.
The reader sees which question went unanswered.
With AparteClient, you write nothing: a failed turn gets this card, and the full error still
reaches your code on the aparte-message-error event.
What the card says
Section titled “What the card says”The reader gets one plain sentence in their language, chosen by the error’s code, never the raw message of the transport or the provider: that one is written for a developer, in English, and often quotes a status or a JSON body. The message stays on the segment, so storage keeps it, and the client puts it on the console when the turn fails.
| Code | Locale key | English |
|---|---|---|
NET_OFFLINE, NET_ERROR | errorUnreachable | The assistant can’t be reached right now. Try again in a moment. |
NET_TIMEOUT | errorTimeout | The answer took too long. Try again in a moment. |
CONFIG_INVALID_KEY (a 401 or a 403: a key, or your own endpoint refusing the session) | errorRefused | The assistant isn’t allowed to answer right now. |
USAGE_RATE_LIMIT (a 429) | errorRateLimited | Too many requests right now. Try again in a moment. |
USAGE_CONTEXT_EXCEEDED | errorTooLong | This conversation is too long for the model. Start a new one. |
PROVIDER_ERROR (a 5xx), PROVIDER_UNAVAILABLE (a 503) | errorFailed | The assistant couldn’t answer. Try again in a moment. |
USAGE_BAD_REQUEST (a 400), PROVIDER_POLICY, PROVIDER_MISCONFIGURED (reached, but set up so it cannot answer: an n8n workflow unpublished or waiting for credentials), CONFIG_INVALID_MODEL, UNKNOWN_ERROR — and a tool whose handler crashed | errorNoAnswer | The assistant couldn’t answer this request. |
“Try again” is said only where a moment can help. A wrong model id or URL is a request that failed,
and reads as one; its reason is on the console. A tool whose handler throws reads as
errorNoAnswer whatever it threw — its own failed fetch is not the assistant being unreachable —
and its row says the tool failed.
An error keeps its own words when they were written for the reader or for the developer setting
the chat up: the turn limit (MAX_TURNS_EXCEEDED, already in the reader’s language), the two
setup errors core raises before any request (CONFIG_NO_PROVIDER, no provider selected;
CONFIG_MISSING_KEY, a provider that is not registered), and an error segment your app or a
plugin adds with a code of its own or none. Every language of
@aparte/locales translates the seven sentences, and extendLocale
changes them.
Variants
Section titled “Variants”A reply cut off midway
Section titled “A reply cut off midway”<aparte-chat-bubble message-id="a1" data-role="assistant"></aparte-chat-bubble>
<script>
// What arrived stays; the error follows it.
document.querySelector('aparte-chat-bubble').setSegments([
{ id: 's1', type: 'text', content: 'Here is the summary of the first two sections. The release fixes' },
{ id: 's2', type: 'error', code: 'PROVIDER_ERROR', content: 'HTTP 502: upstream connect error' },
]);
</script>The card is added after what had already streamed; the partial reply stays.
Customize
Section titled “Customize”aparteGlobalConfig.setErrorRenderer() replaces the card. It receives the sentence the default card shows (absent for an error that keeps its own words), the error’s own message, the
details an app chose to show and the code and returns an element or an HTML string, for a product that adds a “Try again” button
or a link to its status page:
import { aparteGlobalConfig } from '@aparte/core';
aparteGlobalConfig.setErrorRenderer(({ sentence, message }) => {
const card = document.createElement('div');
card.className = 'aparte-alert aparte-alert--danger';
card.textContent = `${sentence ?? message} — see status.example.com`;
return card;
});The code is the machine-readable name of the failure (MAX_TURNS_EXCEEDED, PROVIDER_ERROR…), for your code to branch on: the card never draws it, and carries it as data-error-code for a stylesheet or a test. details stays for text you want the reader to see, a status line or a stack.
import { aparteGlobalConfig, AparteErrorCode } from '@aparte/core';
aparteGlobalConfig.setErrorRenderer(({ sentence, message, code }) => {
const card = document.createElement('div');
card.className = 'aparte-alert aparte-alert--danger';
card.textContent = code === AparteErrorCode.MAX_TURNS_EXCEEDED
? 'The assistant went round in circles. Try asking differently.'
: sentence ?? message;
return card;
});The card you return is yours: a language switch rewrites core’s card, not this one. The built-in card wears the kit’s Alert recipe, so its colours are the alert’s.
Fields
Section titled “Fields”AparteErrorSegment, discriminated by type: 'error'.
| Field | Type | Required | Description |
|---|---|---|---|
content | string | yes | The error’s own message, for storage, the console and a custom error renderer. More |
details | string | — | Text the alert shows under the message, in a block — a stack, a status line an app chooses to show. |
code | string | — | A machine-readable code for the app to branch on — an AparteErrorCode value when core made the error (AparteErrorCode.MAX_TURNS_EXCEEDED, PROVIDER_ERROR…). More |
content — The error’s own message, for storage, the console and a custom error renderer. The
default alert shows it only for an error that keeps its own words (the turn limit, a
setup error, an app’s own code); for any other code it shows the sentence the code
reads as, in the reader’s language.
code — A machine-readable code for the app to branch on — an AparteErrorCode value when
core made the error (AparteErrorCode.MAX_TURNS_EXCEEDED, PROVIDER_ERROR…). Never drawn
itself: it picks the sentence the alert shows, the alert carries it as
data-error-code, and a custom error renderer receives it.
Accessibility
Section titled “Accessibility”- The card’s heading comes from the
errorlocale key, and its sentence from the key its code reads as, both translated with the rest of the chat and rewritten on a language switch. An error that keeps its own words (the turn limit, a setup error, your app’s) shows them as written. - The failure is written, not only coloured: a reader who cannot see red still reads “Error”.
Related
Section titled “Related”- Message — the reply the card belongs to.
- Message actions — retry, once your app turns it on.