Custom Error Pages

Serve beautiful 404, 500, and generic error pages using Barry templates.

Error Pages

Barry lets you define custom error pages using full HTML templates and layouts - with support for components and injected context like status code and path.

File Structure

routes/_error/404.html
routes/_error/500.html
routes/_error/index.html

Each file can include:

  • <!-- layout: components/layouts/error.html --> to define a custom layout
  • {{ define "content" }} blocks like any other template
  • Access to injected variables: .StatusCode, .Message, .Path

Example

<!-- routes/_error/404.html -->
<!-- layout: components/layouts/error.html -->
{{ define "content" }}
  <h1>{{ .StatusCode }} - Page Not Found</h1>
  <p>The page {{ .Path }} does not exist.</p>
{{ end }}

Programmatic Errors

From your index.server.go files, you can return errors like:

return nil, core.NotFound("page not found")

This will render the same 404 template above with proper HTTP headers and context.