Skip to content

Commit bf1bd8a

Browse files
committed
Add custom error pages cookbook entry
1 parent 121828a commit bf1bd8a

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

lib/Thunderhorse/Cookbook.pod

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,33 @@ Thunderhorse::Cookbook - Reusable coding patterns
44

55
=head1 RECIPES
66

7+
=head2 Custom error pages
8+
9+
Making prettier app-wide error pages is easy by overriding
10+
L<Thunderhorse::App/render_error>:
11+
12+
async sub render_error ($self, $controller, $ctx, $code, $message = undef)
13+
{
14+
$controller //= $self->controller;
15+
my $html;
16+
17+
try {
18+
$html = $controller->template("error/$code");
19+
}
20+
catch ($ex) {
21+
$html = $controller->template('error/error', {title => status_message($code)});
22+
}
23+
24+
await $ctx->res->status($code)->html($html);
25+
}
26+
27+
For example for error 404, code above will try to render C<error/404.tt>
28+
template. If it is not found, it will render more generic C<error/error.tt>
29+
instead.
30+
31+
Same can be done on controller level, which means different parts of the system
32+
can use different error pages without any issue.
33+
734
=head2 Reusing common bridge across controllers
835

936
If you need to make a common bridge that will be used across the system, it is

0 commit comments

Comments
 (0)