Error code handling: how to proceed?


I’m looking for a way to handle errors on my website, specially the 403 errors.

There is 2 ways to hit a 403: if the page is hidden and without template <?php if($page->intendedTemplate()!='default' && $page->isInvisible()): ?> (because some pages are just here for their content and populate other pages, not to be displayed, don’t know if it’s a good method) and if a page is forbidden by me <?php if($page->isForbidden()->isTrue()): ?>

For the moment my error page is the same for all errors, and I would like to know if a method exists to adapt it accordingly to the error code sended in the go function, like: <?php go('error', 403) ?>.

Or maybe I have to create one page per error ? In my opinion it would be simpler to keep the error page (as it’s a default kirby page) and read the previous error code, but I don’t know how.

Or maybe I have to handle it via htaccess? So many solutions, I can’t figure what is the best method.

Thank you for your insights.