Documentation · Chapter 05

Turn a failure
into a next action.

A public error page should be calm, brief, and useful. Technical details stay in the development screen or logs.

We improve reading-list without changing its HTTP logic or temporary session storage.

The folder is already configured

The current template points error_views to src/views/errors. PHPAML first looks for the status file, such as 404.php, then default.php when no specific file exists.

phpaml — zsh
src/views/errors/404.php
src/views/errors/500.php
src/views/errors/default.php

A useful 404 page

src/views/errors/404.php

phpaml — zsh
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>404 — Page not found</title>
    <link rel="stylesheet" href="/css/error.css">
</head>
<body>
<main>
    <p>404</p>
    <h1>This page cannot be found.</h1>
    <p>Check the address or return to your library.</p>
    <a href="/books">View my books</a>
</main>
</body>
</html>

A generic page without leakage

src/views/errors/default.php

phpaml — zsh
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title><?= (int) $status ?> — Error</title></head>
<body>
<main>
    <p><?= (int) $status ?></p>
    <h1><?= htmlspecialchars($title, ENT_QUOTES, 'UTF-8') ?></h1>
    <p>The request could not be completed.</p>
    <?php if ($requestId !== null): ?>
        <p>Reference: <code><?= htmlspecialchars($requestId, ENT_QUOTES, 'UTF-8') ?></code></p>
    <?php endif; ?>
</main>
</body>
</html>

The reference number helps find the incident in logs without showing the visitor a trace, internal paths, or secrets.

Which file for which problem?

404.phpunknown address
500.phpunexpected internal error
default.php419, 422, 429, 503, and others
Development and production differ

With APP_DEBUG enabled, PHPAML may display its detailed panel for fixing code. In production, visitors must receive the safe generic page.