Error State

A message for a load that failed, in the layout of an empty state, with a way to try again.

Something went wrong on our side
Try again in a moment. If it keeps happening, contact support.
import {
  ERROR_KIND_ICONS,
  ERROR_STATE_MESSAGES,

When to use it

Use an error state in the place where content should have been, when loading it failed: a table that could not load, a chart, a whole page. It says what went wrong in plain words and, when trying again could help, gives a button to do so.

It is for a failed load. For a problem with something the person typed, use a Field error. For a message about the data that is still on screen, use an Alert. When the load worked but there is nothing to show, use Empty.

You will rarely build one by hand. Async Content picks the right words for the kind of error and draws this component for you. Use the parts on their own when you want a custom layout.

Import

import {
  ErrorState,
  ErrorStateMedia,
  ErrorStateHeader,
  ErrorStateTitle,
  ErrorStateDescription,
  ErrorStateActions,
  ErrorStateRetry,
  ErrorStateDetails,
} from "@hel/ui/error-state"

Anatomy

An error state is built like Empty, and has the same size.

  • ErrorState is the wrapper. It is announced to screen readers when it appears. Set announce={false} when it is on the page from the start, so it does not interrupt.
  • ErrorStateMedia is the icon tile, tinted for an error. tone="neutral" makes it the plain tile, for a state that is not really a failure, such as being offline.
  • ErrorStateHeader holds the ErrorStateTitle and the ErrorStateDescription.
  • ErrorStateActions holds the buttons. ErrorStateRetry is the "Try again" button.
  • ErrorStateDetails is a folded section for support, such as a request id or an error code.

Kinds of errors

Not every failure deserves the same words. The library sorts an error into one of five kinds from its status, and each has its own icon and text.

KindMeant forOffers retry
offlineNo connectionNo
forbiddenStatus 401 or 403No
notFoundStatus 404 or 410No
serverStatus 500 and aboveYes
unknownAnything elseYes

Retrying is only offered where asking again can change the answer. Asking again for something you may not see, or that is gone, gives the same answer.

ERROR_KIND_ICONS and errorKindText give you the icon and the words of a kind, as the example does. describeError and useErrorDescription turn a real error into its kind, request id and wording. An app can change them all in one place through errors.describe in its config.

offline
You're offline
This will load when you're back online.
forbidden
You don't have access
Ask an admin to give you access to this.
notFound
We couldn't find this
It may have been moved or deleted.
unknown
Couldn't load this
Check your connection and try again.
import {
  ERROR_KIND_ICONS,
  ERROR_STATE_MESSAGES,

Retrying

ErrorStateRetry takes pending, which makes it spin and blocks a second press. If the retry fails again, say so, and after a couple of failures give people another way out, such as a link to support. This example fails every time, so you can see all three stages.

Something went wrong on our side
Try again in a moment. If it keeps happening, contact support.
import * as React from "react"

import { Button } from "@hel/ui/button"

Props

ErrorState

PropTypeDefault
size"sm" | "md""md"
announcebooleantrue

ErrorStateMedia

PropTypeDefault
iconLucideIconA circle with an exclamation mark
tone"error" | "neutral""error"

ErrorStateRetry

PropTypeDefault
pendingbooleanfalse
messagesPartial<ErrorStateMessages>Built-in text
localestringThe app's locale

It also takes the props of a Button.