Created
March 14, 2012 06:10
-
-
Save hisaichi5518/2034515 to your computer and use it in GitHub Desktop.
こういう感じでMaltsのto_appを上書きすればいい気がする。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package MyApp::Web; | |
| use 5.10.1; | |
| use strict; | |
| use warnings; | |
| use parent qw/Malts Malts::Web/; | |
| use Log::Minimal; | |
| # ...略 | |
| sub to_app { | |
| my ($self) = @_; | |
| return sub { | |
| my ($env) = @_; | |
| local $Log::Minimal::DIE = \&_throw; | |
| my $res = eval { $self->SUPER::to_app->($env) }; | |
| return _catch_error($@) if $@; | |
| return $res; | |
| }; | |
| } | |
| sub _throw { | |
| my ($time, $type, $message, $trace, $raw_message) = @_; | |
| die { | |
| code => 500, | |
| message => 'Unknown Error!', | |
| time => $time, | |
| type => $type, | |
| trace => $trace, | |
| (ref $raw_message ne 'HASH' | |
| ? (message => $raw_message) | |
| : %$raw_message), | |
| }; | |
| } | |
| sub _catch_error { | |
| my ($e) = @_; | |
| if (ref $e ne 'HASH') { | |
| $e = { | |
| code => 500, | |
| message => $e, | |
| }; | |
| } | |
| my $c = Malts->context; | |
| my $res = ...; # レスポンスオブジェクトを作る。 | |
| return $res->finalize; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment