Catalyst::ControllerRole::CatchErrors - custom error handling in your controller.
version 0.05
package MyApp::Controller::Root; use Moose; BEGIN { extends 'Catalyst::Controller' } with 'Catalyst::ControllerRole::CatchErrors'; sub catch_errors : Private { my ($self, $c, @errors) = @_; # stuff }
If an action throws an error the default behaviour of Catalyst is to render a default error page and set the response code to 500. One usecase where this is problematic is if you have a REST Controller using Catalyst::Action::REST. Catalyst::ControllerRole::CatchErrors requires a catch_errors action that receives an array of all errors that occurred during the request.
Catalyst::ControllerRole::CatchErrors
catch_errors
You can rethrow the error in catch_errors. Catalyst::ControllerRole::CatchErrors passes a copy of the errors to your method and clears the original ones before calling catch_errors.
By default, Catalyst does not catch errors confirming to the interface described by Plack::Middleware::HTTPExceptions and lets the middleware deal with it. You can enable the always_catch_http_exceptions in your Catalyst configuration to let Catalyst::ControllerRole::CatchErrors catch these errors as well.
Catalyst
always_catch_http_exceptions
David Schmidt <davewood@cpan.org>
This software is copyright (c) 2014 by David Schmidt.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Catalyst::ControllerRole::CatchErrors, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::ControllerRole::CatchErrors
CPAN shell
perl -MCPAN -e shell install Catalyst::ControllerRole::CatchErrors
For more information on module installation, please visit the detailed CPAN module installation guide.