b040b1c063fb54666945e29b15663ce01617acd8
[catagits/Catalyst-Runtime.git] / t / lib / Catalyst / Plugin / Test / Errors.pm
1 package Catalyst::Plugin::Test::Errors;
2
3 use strict;
4 use NEXT;
5
6 sub error {
7     my $c = shift;
8
9     unless ( $_[0] ) {
10         return $c->NEXT::error(@_);
11     }
12
13     if ( $_[0] =~ /^(Unknown resource|No default action defined)/ ) {
14         $c->response->status(404);
15     }
16     
17     if ( $_[0] =~ /^Couldn\'t forward/ ) {
18         $c->response->status(404);
19     }    
20
21     if ( $_[0] =~ /^Caught exception/ ) {
22         $c->response->status(500);
23     }
24
25     my $error = $_[0];
26     $error =~ s/\n/, /g;
27
28     $c->response->headers->push_header( 'X-Catalyst-Error' => $error );
29
30     $c->NEXT::error(@_);
31 }
32
33 1;