NAME

Catalyst::ControllerRole::CatchErrors - custom error handling in your controller.

VERSION

version 0.05

SYNOPSIS

    package MyApp::Controller::Root;
    use Moose;
    BEGIN { extends 'Catalyst::Controller' }
    with 'Catalyst::ControllerRole::CatchErrors';

    sub catch_errors : Private {
        my ($self, $c, @errors) = @_;
        # stuff
    }

DESCRIPTION

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.

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.

HTTP::Exception 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.

AUTHOR

David Schmidt <davewood@cpan.org>

COPYRIGHT AND LICENSE

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.