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

David Schmidt davewood at gmx.at
Tue Nov 9 15:06:39 GMT 2010


On Tue, Nov 9, 2010 at 11:38 AM, Eden Cardim <edencardim at gmail.com> wrote:
>>>>>> "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.


I tend to put related actions into a controller. E.g.: all actions
dealing with artists into the Artists.pm controller and so on.
You advise (as I understood) means having an additional controller for
every controller where I want to support XHR requests.

Is there a flaw in how I lay out my controllers?

david



More information about the Catalyst mailing list