File: Errors.pm

package info (click to toggle)
libcatalyst-perl 5.90132-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,016 kB
  • sloc: perl: 11,061; makefile: 7
file content (33 lines) | stat: -rw-r--r-- 605 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package Catalyst::Plugin::Test::Errors;

use strict;
use MRO::Compat;

sub error {
    my $c = shift;

    unless ( $_[0] ) {
        return $c->next::method(@_);
    }

    if ( $_[0] =~ /^(Unknown resource|No default action defined)/ ) {
        $c->response->status(404);
    }

    if ( $_[0] =~ /^Couldn\'t forward/ ) {
        $c->response->status(404);
    }

    if ( $_[0] =~ /^Caught exception/ ) {
        $c->response->status(500);
    }

    my $error = $_[0];
    $error =~ s/\n/, /g;

    $c->response->headers->push_header( 'X-Catalyst-Error' => $error );

    $c->next::method(@_);
}

1;