Browse Source

* fixes

master
Alex 'AdUser' Z 7 years ago
parent
commit
68b26d2272
  1. 2
      lib/CMTD/Helpers.pm
  2. 15
      lib/CMTD/Main.pm

2
lib/CMTD/Helpers.pm

@ -10,7 +10,7 @@ sub register {
my ($self, $app) = @_; my ($self, $app) = @_;
$app->helper(referrer => sub { $app->helper(referrer => sub {
my ($c, $url) = @_; my ($c) = @_;
my $url = $c->req->headers->referrer || my $url = $c->req->headers->referrer ||
$c->req->param('url'); $c->req->param('url');
return $url; return $url;

15
lib/CMTD/Main.pm

@ -7,7 +7,7 @@ use utf8;
use Mojo::Base 'Mojolicious::Controller'; use Mojo::Base 'Mojolicious::Controller';
sub index { sub index {
my $self = shift; my ($self) = @_;
$self->render(text => 'Go away!'); $self->render(text => 'Go away!');
} }
@ -21,26 +21,29 @@ sub c_list {
sub c_add { sub c_add {
my ($self) = @_; my ($self) = @_;
unless (my $ref = $self->referrer and ref $ref eq 'HASH') { my $ref = $self->referrer;
unless ($ref and ref($ref) eq 'HASH') {
$self->res->code(400); $self->res->code(400);
$self->render(text => "Can't detect referred page"); $self->render(text => "can't detect referred page");
return; return;
} }
unless (my $site = $self->app->sites->{ $ref->{site} }) { my $site = $self->app->sites->{ $ref->{site} };
unless ($site and ref($site) eq 'HASH') {
$self->res->code(400); $self->res->code(400);
$self->render(text => "No such site"); $self->render(text => "no such site");
return; return;
} }
eval { eval {
1;
} or do { } or do {
chomp $@; chomp $@;
my $msg = sprintf "Error when listing comments for %s/%s: %s", my $msg = sprintf "Error when listing comments for %s/%s: %s",
$ref->{site}, $ref->{pid}, $@; $ref->{site}, $ref->{pid}, $@;
$self->app->log->error($msg); $self->app->log->error($msg);
$self->res->code(500); $self->res->code(500);
$self->render(text => 'Internal error'); $self->render(text => 'internal error');
}; };
} }

Loading…
Cancel
Save