MARY.WIN

RUSTY — INERTIA — CHAPTER 09

Error
Pages

Chapter 9 of 10 in Inertia on Rust, draft chapters on the Inertia adapter for Rust.

Two different things go wrong in an Inertia application: a handler decides the answer is an error, or a prop fails after the handler has already returned. In this chapter we'll render an error as a page, see what the crate does with a failing prop, and look at the two ways to keep one failure from taking the page down.

This chapter assumes Chapter 6, since the failures here happen in prop callbacks. It does not cover validation errors; those are Chapter 4.

An error is a page with a status

The report prop trusted its upstream service. The service was down. The handler had returned by then, satisfied, with a callback still to run. The callback ran during rendering, failed, and the customer received three words: Internal Server Error.

Sometimes the right response to a request is an error the user can read. Thankfully, an error page is an ordinary page returned with a status code. Take a look at Example 9-1.

Example 9-1. A 404 that is still an Inertia page

pub async fn missing(inertia: Inertia) -> Response {
    (StatusCode::NOT_FOUND, inertia.render("Error", props! { status => 404 })).into_response()
}

There is one new piece here. A tuple of a status and a render is a response, so the client receives a 404 whose body is a page object for the Error component, shared props included.

When a prop fails

A prop callback may return a Result. Example 9-2 has one that always fails.

Example 9-2. A prop that fails

async fn load_report() -> Result<u32, std::io::Error> {
    Err(std::io::Error::other("The report service is down"))
}

pub async fn report(inertia: Inertia) -> inertia::Response {
    inertia.render("Reports/Show", props! { "report" => inertia::try_lazy(load_report) })
}

try_lazy takes a callback that returns a Result. When it returns an error, the whole response fails: the layer logs the error and replies 500 with a plain-text body. No page is rendered, so no error component is shown.

You can also rescue a prop. Add .rescue(), and its failure is reported in a rescuedProps field on the page while the rest of the page goes out as normal (see Example 9-3).

Example 9-3. A rescued, deferred prop

props! { "title" => "Q4", "report" => inertia::try_lazy(load_report).deferred().rescue() }

A partial reload asking for report gets a 200 with this page:

{"component":"Reports/Show","props":{"errors":{}},"url":"/report-rescued","version":"1",
 "sharedProps":["errors","app_name","auth"],"rescuedProps":["report"]}

The second way is to replace the 500. InertiaLayer::handle_with runs the layer's logic with a callback for a failed prop, and that callback may return a page render, such as your own error page. The crate's test suite exercises this; this chapter's listings do not. If you're unsure which to reach for, I'd rescue the props a page can live without and leave the rest to fail loudly.

What this chapter leaves open

So a rescued prop keeps the page alive, and the response is a 200. Your monitoring counts status codes. What tells you the report service has been down since morning? Does anything on the client read rescuedProps, and what does the user see where the report should be?

Testing

Example 9-4 fails if a prop error starts producing a page, or stops producing a 500.

Example 9-4. A failing prop

let reply = send(&app(), visit("GET", "/report").body(Body::empty()).unwrap()).await;

assert_eq!(reply.status, StatusCode::INTERNAL_SERVER_ERROR);
assert_eq!(reply.body, "Internal Server Error");

TL;DR

An error page is a render returned with a status code. A prop callback that returns an error fails the whole response with a logged 500, unless the prop is rescued, in which case the page is sent and the prop's name appears in rescuedProps. handle_with lets you answer a failed prop with a response of your own.

The sources.

Each line is a claim this chapter makes and where to look. Checked on 2026-11-29 against inertia-laravel-rust at commit 3ccc126.

CLAIM × WHERE — 8
  • A (status, render) tuple responds with that status and a pageR1 · tests/axum.rs L38-L41
  • A prop callback may return a Result; its error fails the response unless rescuedR1 · src/props/mod.rs L266-L267, L290-L314
  • A failed prop is logged and the response is a 500 with a plain-text bodyR1 · src/axum/layer.rs L59-L74, L131-L133
  • rescue reports the failure in rescuedProps instead of failing the responseR1 · src/props/prop.rs L162-L167
  • handle_with answers a failed prop with a callback whose response may be a page renderR1 · src/axum/layer.rs L76-L93, L111-L117; tests/axum.rs L358-L393
  • The extractor without a layer responds 500R1 · src/axum/extract.rs L31-L48
  • An error page includes shared propsrun · test output an_error_page_is_a_page_with_a_status
  • Scene: the callback runs after the handler has returnedR1 · src/props/mod.rs L262-L264

R1: inertiajs/inertia-laravel-rust @3ccc126a24c8fb5bddb140876a1825292c0d216c
run: Observed by running the chapter listings on 2026-11-29; the code that produces it was not read