The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

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

VERSION

version 0.01

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. If you apply the Catalyst::ControllerRole::CatchErrors role to your controller you can provide a catch_errors action that receives an array of all errors that occurred during the request and do with them whatever you want. You can even rethrow the error. Catalyst::ControllerRole::CatchErrors passes a copy of the errors to your method and clears the original ones before calling catch_errors.

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.