Skip to content

Commit

Permalink
allow errors to have varying content types
Browse files Browse the repository at this point in the history
  • Loading branch information
Chip committed Feb 17, 2011
1 parent 08c855f commit 3733af2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/Tatsumaki/Error.pm
Expand Up @@ -18,13 +18,14 @@ extends 'Tatsumaki::Error';

use overload q("") => sub { $_[0]->message }, fallback => 1;
has code => (is => 'rw', isa => 'Int');
has content_type => (is => 'rw', isa => 'Str', default => 'text/plain');
has message => (is => 'rw', isa => 'Str');

around BUILDARGS => sub {
my $orig = shift;
my($class, $code, $msg) = @_;
my($class, $code, $msg, $ct) = @_;
$msg ||= HTTP::Status::status_message($code);
$class->$orig(code => $code, message => $msg);
$class->$orig(code => $code, content_type => ($ct // 'text/plain'), message => $msg);
};

package Tatsumaki::Error;
Expand Down
2 changes: 1 addition & 1 deletion lib/Tatsumaki/Handler.pm
Expand Up @@ -99,7 +99,7 @@ sub run {

my $catch = sub {
if ($_->isa('Tatsumaki::Error::HTTP')) {
return [ $_->code, [ 'Content-Type' => 'text/plain' ], [ $_->message ] ];
return [ $_->code, [ 'Content-Type' => $_->content_type ], [ $_->message ] ];
} else {
$self->log($_);
return [ 500, [ 'Content-Type' => 'text/plain' ], [ "Internal Server Error" ] ];
Expand Down

0 comments on commit 3733af2

Please sign in to comment.