error is now in Context (t/aggregate/live_recursion.t and others)
[catagits/Catalyst-Runtime.git] / t / lib / Catalyst / TraitFor / Context / TestErrors.pm
diff --git a/t/lib/Catalyst/TraitFor/Context/TestErrors.pm b/t/lib/Catalyst/TraitFor/Context/TestErrors.pm
new file mode 100644 (file)
index 0000000..0597ffb
--- /dev/null
@@ -0,0 +1,28 @@
+package Catalyst::TraitFor::Context::TestErrors;
+
+use Moose::Role;
+
+before error => sub {
+    my $c = shift;
+    unless ( $_[0] ) {
+        return;
+    }
+
+    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 );
+};
+
+1;