Dancer2-Plugin-LogReport
view release on metacpan or search on metacpan
lib/Dancer2/Plugin/LogReport.pod view on Meta::CPAN
return if $dsl->app->request->uri !~ m!^/api/!;
status $reason eq 'PANIC' ? 'Internal Server Error' : 'Bad Request';
$dsl->send_as(JSON => {
error => 1,
error_description => $msg->toString,
}, {
content_type => 'application/json; charset=UTF-8',
});
};
» example: Return JSON responses for requests with content-type of application/json
fatal_handler sub {
my ($dsl, $msg, $reason, $default) = @_;
(my $ctype = $dsl->request->header('content-type')) =~ s/;.*//;
return if $ctype ne 'application/json';
status $reason eq 'PANIC' ? 'Internal Server Error' : 'Bad Request';
$dsl->send_as(JSON => {
error => 1,
description => $msg->toString,
}, {
content_type => 'application/json; charset=UTF-8',
});
};
( run in 1.782 second using v1.01-cache-2.11-cpan-524268b4103 )