[Catalyst] Custom finalize_error

Jim Spath jspath at pangeamedia.com
Mon Apr 2 22:39:23 GMT 2007


Jim Spath wrote:
> Jason Kohles wrote:
>> On Apr 2, 2007, at 4:13 PM, Jim Spath wrote:
>>
>>> I wanted to get rid of the "Please come back later" error page, so I 
>>> defined my own finalize_error() in MyApp.pm as mentioned in this post:
>>>
>>> http://www.mail-archive.com/catalyst@lists.rawmode.org/msg04542.html
>>>
>>> It looks like:
>>>
>>> sub finalize_error {
>>>   my ($self, $c) = @_;
>>>
>>>   $c->stash->{'template'} = 'error.tt2';
>>>
>>> }
>>>
>>> The "Please come back later" page no longer appears, but now the page 
>>> is simply blank.  I've double checked to make sure the error.tt2 
>>> template is accessible via Catalyst and it is, so I'm unsure where to 
>>> go from here.
>>>
>> finalize_error is called long after the view processing has already 
>> been done, if you want to use a template to put a page there, you have 
>> to build your own Template object and process the template yourself.
> 
> Ah.  Great, thanks!  I got it to work with the following code:
> 
> sub finalize_error {
>   my ($c) = @_;
> 
>   $c->response->content_type('text/html; charset=utf-8');
>   $c->response->body($c->view('Website')->render($c, 'error.tt2'));
>   $c->response->status(500);
> 
> }

As an aside, what are the advantages/disadvantages of defining my own 
finalize_error() instead of handling errors in end() as described in the 
Catalyst Cookbook:

http://search.cpan.org/dist/Catalyst-Manual/lib/Catalyst/Manual/Cookbook.pod#Delivering_a_Custom_Error_Page



More information about the Catalyst mailing list