[Catalyst] error handling (Chain where ajax and non-ajax actions chain off)

Eden Cardim edencardim at gmail.com
Tue Nov 9 10:38:59 GMT 2010


>>>>> "David" == David Schmidt <davewood at gmx.at> writes:

    David> Hello list Both ajax and non-ajax actions chain off the same
    David> action (base_with_id). If an error occurs (like the resource
    David> doesn't exist) I detach to '/error404' in my Root Controller.
    David> I just introduced the ajax stuff and before that 'error404'
    David> simply rendered an error template. Now I'd like to check if
    David> it is an xmlhttp request using
    David> http://search.cpan.org/~flora/Catalyst-TraitFor-Request-XMLHttpRequest-0.01/
    David> and then either render the error template like before OR use
    David> the status_not_found() helper from
    David> http://search.cpan.org/~bobtfish/Catalyst-Action-REST-0.87/

    David> To use status_not_found I need to extend my Root Controller
    David> from Catalyst::Controller::REST

    David> That'd mean i have to check the type of request again in my
    David> roots end method to avoid rendering of the template.


    David> #Root.pm
    David> sub render : ActionClass('RenderView') {}
    David> sub end :Private {
    David>     my ($self, $c) = @_;
    David>     unless ($c->request->is_xhr) {
    David>         $c->forward('render');
    David>     }
    David> }

    David> Any comments on that solution are appreciated as are pointers
    David> to alternatives.

Put the ajax code into a separate controller with an XHR-specific end
action (probably empty, for your case) and chain from there.

-- 
     Eden Cardim            Need help with your perl Catalyst or DBIx::Class project?
   Software Engineer                   http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.        Want a managed development or deployment platform?
http://blog.edencardim.com             http://www.shadowcat.co.uk/servers/



More information about the Catalyst mailing list