Skip to content
Layout Error

Error

The content of an error page: status code, message and a way back.

On this page

Examples

Not found

Use it as the body of the NotFound page.

404

Page not found

The page you are looking for does not exist or has moved.

Razor
@* In a Blazor app, the body of the NotFound page: <KlyError StatusCode="404" />. HeadingLevel="3" only keeps this page's outline in order. *@
<div class="w-full overflow-hidden rounded-xl border border-(--klyroo-border)">
    <KlyError StatusCode="404" HeadingLevel="3" data-testid="error" />
</div>

Error boundary

Pass the exception from ErrorContent; the details are shown only on request.

500

Something went wrong

The report could not be generated.

Razor
@* The ErrorContent of an ErrorBoundary hands over the exception: <KlyError Exception="exception" />.
   Its message stays hidden unless ShowDetails is set, because exception messages can leak internals. *@
<div class="w-full overflow-hidden rounded-xl border border-(--klyroo-border)">
    <KlyError Exception="_exception" ShowDetails HeadingLevel="3" Clear="false" data-testid="error-boundary">
        <Actions>
            <KlyButton Label="Try again" Href="/components/error" />
            <KlyButton Label="Contact support" Variant="ButtonVariant.Outline" Color="KlyColor.Neutral" Href="/docs" />
        </Actions>
    </KlyError>
</div>

@code {
    private readonly Exception _exception = new InvalidOperationException("The report could not be generated.");
}

API

KlyError

Content of an error page: status code, title, message and a way back. Use it as the body of a not found page or inside an error boundary.

Parameters

Name Type Default Description
Class string Classes added to the root element, merged last so they win over the theme.
Clear bool true Shows the button that leads back to Href . Ignored when Actions is set.
ClearLabel string Text of the back button. Defaults to the built-in text.
Exception Exception The exception of an ErrorBoundary . Sets the status code to 500 when none is given.
HeadingLevel int 1 Level of the title heading, 1 to 6: 1 by default, 2 when the error replaces a part of a page.
Href string "./" Where the back button goes. The default "./" is the home of the app: relative to <base href> , so it is right below a path base too.
Message string The explanation under the title. Defaults to a text for StatusCode .
ShowDetails bool false Shows the message of Exception . Leave it off in production: exception messages can leak internals.
StatusCode int? The HTTP status code, shown above the title. 404, 403 and 500 have built-in texts.
StatusMessage string The title. Defaults to a text for StatusCode .
Ui ErrorUi Per-instance class overrides of the slots of the error, see ErrorUi . They are merged after the theme and the Class parameter wins on the root slot.

Slots

Name Type Description
Actions RenderFragment Replaces the back button.
ChildContent RenderFragment Extra content between the message and the actions.

Ui slots

Ui takes a ErrorUi with one class string per slot, merged after the theme.

Slot Styles
Root Classes merged into the root slot of KlyError , after the theme and the app configuration.
StatusCode Classes merged into the statusCode slot of KlyError , after the theme and the app configuration.
StatusMessage Classes merged into the statusMessage slot of KlyError , after the theme and the app configuration.
Message Classes merged into the message slot of KlyError , after the theme and the app configuration.
Actions Classes merged into the actions slot of KlyError , after the theme and the app configuration.