NAME

Catalyst::ActionRole::RenderErrors - Automatically return an error page

SYNOPSIS

    package Example::Controller::Root;

    use Moose;
    use MooseX::MethodAttributes;

    extends 'Catalyst::Controller';

    sub root :Chained(/) PathPart('') CaptureArgs(0) {} 

      sub not_found :Chained(root) PathPart('') Args {
        my ($self, $c, @args) = @_;
        $c->detach_error(404);
      }

      sub die :Chained(root) PathPart(die) Args(0) {
        die "saefdsdfsfs";
      }

    sub end :Does(RenderErrors) { }

    __PACKAGE__->config(namespace=>'');
    __PACKAGE__->meta->make_immutable;
  

DESCRIPTION

Handles any uncaught errors (defined as "there's something in $c-errors>"). If in Debug mode this just passes the errors down to the default Catalyst debugging error response. Otherwise it converts to a Bad Request and dispatches an error page via $c-dispatch_error(500, errors=>\@errors)>. This will give you a servicable http 500 error via content negotiation which you can customize as desired (see CatalystX::Errors).

If the first error in $c-error> is an object that does either code or status then we use that error to get the HTTP status code and any additional meta or errors arguments (if those methods exist on the object. If its not then we just return a simple HTTP 500 Bad request. In that case we won't return any information in $c-error> since that might leack contain Perl debugging info.

Useful for API work since the default Catalyst error page is in HTML and if your client is requesting JSON we'll return a properly formatted response in application/json.

SEE ALSO

CatalystX::Errors.

AUTHOR

CatalystX::Errors.

COPYRIGHT & LICENSE

CatalystX::Errors.