error is now in Context (t/aggregate/live_recursion.t and others)
[catagits/Catalyst-Runtime.git] / t / lib / Catalyst / TraitFor / Context / TestErrors.pm
1 package Catalyst::TraitFor::Context::TestErrors;
2
3 use Moose::Role;
4
5 before error => sub {
6     my $c = shift;
7     unless ( $_[0] ) {
8         return;
9     }
10
11     if ( $_[0] =~ /^(Unknown resource|No default action defined)/ ) {
12         $c->response->status(404);
13     }
14     
15     if ( $_[0] =~ /^Couldn\'t forward/ ) {
16         $c->response->status(404);
17     }    
18
19     if ( $_[0] =~ /^Caught exception/ ) {
20         $c->response->status(500);
21     }
22
23     my $error = $_[0];
24     $error =~ s/\n/, /g;
25     $c->response->headers->push_header( 'X-Catalyst-Error' => $error );
26 };
27
28 1;