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::Action::RenderView::ErrorHandler - Custom errorhandling in deployed applications

VERSION

This document describes Catalyst::Action::RenderView::ErrorHandler version 0.0100

SYNOPSIS

    sub end : ActionClass('RenderView::ErrorHandler') {}

  

DESCRIPTION

We all dread the Please come back later screen. Its uninformative, non- helpful, and in general an awfull default thing to do.

This module lets the developer configure what happens in case of emergency.

If you want the errors emailed to you? You can have it.
Want them logged somewhere as well? suresure, we will do it.
Custom errorpage that fits your design you say? Aw come on :)

CONFIGURATION AND ENVIRONMENT

We take our configuration from $c->config->{'error_handler'}. If you do no configuration, the default is to look for the file 'root/static/error.html', and serve that as a static file. If all you want is to show a custom, static, error page, all you have to do is install the module and add it to your end action.

OPTIONS

actions

Is an array of actions you want taken. Each value should be an hashref with atleast the following keys:

type

Can be Log for builtin, or you can prefix it with a +, then we will use it as a fully qualified class name.

A typical example of an action one might want is Email, which could for instance use Catalyst::View::Email to send an email to the developers.

id

The id you want to have for this action

handlers

Configuration as to what to do when an error occurs. We always need to show something to the user, so thats a given. Each handler represents an error state, and a given handler can perform any given number of actions in addition to rendering or sending something to the browser/client.

HTTP status codes (404, 500 etc)
HTTP status code groups (4xx, 5xx etc)
"fallback" - default action taken on error.

The action is decided in that order.

template

Will be sent to your default_view for processing. Can use c.errors as needed

static

Will be read and served as a static file. This is the only option for fallback, since fallback will be used in case rendering a template failed for some reason.

If the given string begins with an '/', we treat it as an absolute path and try to read it directly. If not, we pass it trough $c->path_to() to get an absolute path to read from.

EXAMPLE

    error_handler:
        actions:
            # Note that Email is only provided here as an example, it does not
            # exist.
            - type: Email
              id: email-devel
              to: andreas@example.com
              subject: __MYAPP__ errors:
            - type: Log
              id: log-server
              level: error
        handlers:
            5xx:
                template: root/error/5xx.tt
                actions:
                    - email-devel
                    - log-server
            500:
                template: root/error/500.tt
                actions:
                    - log-server
            fallback:
                static: root/static/error.html
                actions:
                    - email-devel

INTERFACE

IMPLEMENTED METHODS

execute

Implemented to comply with Catalyst::Action interface.

It checks if there are errors, if not it it simply returns, assuming Catalyst::Action::RenderView has handled the job. If there are errors we parse the configuration and try to build our handlers.

Then it calls $self->handle.

METHODS

handle

Handles a request, by finding the propper handler.

Once a handler is found, it calls render if there are statics or templates, and then performs all actions (if any).

render

Given either a static file or a template, it will attempt to render it and send it to $context->res->body.

INHERITED METHODS

meta

Inherited from Moose

DEPENDENCIES

Catalyst::Action::RenderView

INCOMPATIBILITIES

None reported.

BUGS AND LIMITATIONS

No bugs have been reported.

AUTHOR

Andreas Marienborg <andreas@startsiden.no>

LICENCE AND COPYRIGHT

Copyright (c) 2007, Andreas Marienborg <andreas@startsiden.no>. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.