Skip to content

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'
On this page
Open

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.

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.

CodeLocale keyEnglish
NET_OFFLINE, NET_ERRORerrorUnreachableThe assistant can’t be reached right now. Try again in a moment.
NET_TIMEOUTerrorTimeoutThe 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)errorRefusedThe assistant isn’t allowed to answer right now.
USAGE_RATE_LIMIT (a 429)errorRateLimitedToo many requests right now. Try again in a moment.
USAGE_CONTEXT_EXCEEDEDerrorTooLongThis conversation is too long for the model. Start a new one.
PROVIDER_ERROR (a 5xx), PROVIDER_UNAVAILABLE (a 503)errorFailedThe 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 crashederrorNoAnswerThe 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.

Open

The card is added after what had already streamed; the partial reply stays.

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:

ts
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.

ts
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.

AparteErrorSegment, discriminated by type: 'error'.

FieldTypeRequiredDescription
contentstringyesThe error’s own message, for storage, the console and a custom error renderer. More
detailsstring—Text the alert shows under the message, in a block — a stack, a status line an app chooses to show.
codestring—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.

  • The card’s heading comes from the error locale 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”.