Error Pages (http-error)

Hi everybody,

I would like to know how you guys handle your customs error pages?!
Do you use “response::error” or “response::header” from the toolkit api?

How is Kirby handling with errors generally?
Is everything returned to the error.php under templates? No matter if it’s a 404 or a 500?

Would be great to hear some different approaches :blush:

error.php is the default template of the error page in the root of the content directory. It is used if no plugin stopped execution (for example with a route) and the page was not found. So yes, it’s a 404 error page. You don’t need to modify the HTTP status code, as it’s always set to 404 in that case.

HTTP 500 is not handled by error.php, because it’s thrown if something goes very wrong. Normally this should not happen, so you don’t need a custom error page for that. If you really do, you can use the Apache ErrorDocument directive for that and serve a static error page.

Thank you for your reply.

Okay, maybe the 500 error was a bad example. But what about 400 or 403? I want to achieve a single error page which can be used to show different errors.

That depends on your implementation and use-case. Do you want to handle these kinds of errors in routes, plugins or in templates directly? Or to be more general: When are the errors thrown?

If you have control over the place the errors are thrown and you aren’t already in the template, you can use site()->visit('error'); to select the error page. Your error page will need to contain the logic to send the appropriate status code though.

Good questions…
I should spend a few more thoughts about that :-/

Thanks for the input