## Demo: error
### ErrorDemo.svelte
```svelte
Mochi catches any throw from a page's Try it:
A custom error component receives a single This site's
Watch your dev server output while clicking the links above — each visit logs one
serverProps resolver or Svelte <script>, plus any request that doesn't match a route, and renders the
built-in default error page. Pass your own errorPage to Mochi.serve() to replace it. The handleError hook runs for every error — use it
to log, forward to an error tracker, sanitize the message, or return a Response to short-circuit rendering.
/demos/error/500
the page's <script> throws during SSR
/demos/error/404
the serverProps resolver calls error(404, ...)
/does-not-exist
no route matches — handleError fires with error: null, then the error page renders with status 404
/demos/error/redirect
the page throws, but handleError returns Response.redirect(...) — you land back on this page instead of seeing the error component
error prop with status,
message, and (in development only) stack — typed as
MochiErrorProps.
handleError:handleError: line via logger from mochi-framework. Unmatched routes log error null; SSR throws log
error present.
You should never see this — the page throws during SSR.
``` ### routes.ts ```ts import { Mochi, error } from 'mochi-framework'; import type { MochiRouteValue } from 'mochi-framework'; export const routes: Record