Report 404s better
This commit is contained in:
parent
65bb0ef5a0
commit
f8bdcc9201
|
@ -58,7 +58,9 @@ Run the tests locally (against development environment):
|
|||
|
||||
## TODOs
|
||||
|
||||
1. Report 404s better (thread by id and remark by id)
|
||||
1. Clean-up 404 stuff and variable checking (what's up with
|
||||
`$last_page` checking?)
|
||||
1. Don't allow non-mods to view hidden posts at all
|
||||
1. "All new posts flagged" mode (require approval for new posts)
|
||||
1. Tests for mod-only user?
|
||||
|
||||
|
|
|
@ -6,9 +6,15 @@ sub by_id($self) {
|
|||
my $remark_id = $self->param('remark_id');
|
||||
my $remark = $self->remark->by_id($remark_id);
|
||||
|
||||
$self->stash(status => 404) unless $remark->{'id'};
|
||||
|
||||
$self->stash(remark => $remark);
|
||||
if (my $remark_id = $remark->{'id'}) {
|
||||
$self->stash(remark => $remark)
|
||||
}
|
||||
else {
|
||||
$self->stash(
|
||||
remark => {},
|
||||
error => 'Remark not found 🤷'
|
||||
)
|
||||
}
|
||||
|
||||
$self->render;
|
||||
}
|
||||
|
|
|
@ -64,13 +64,19 @@ sub by_id($self) {
|
|||
$self->stash(
|
||||
thread => {},
|
||||
remarks => [],
|
||||
status => 404
|
||||
status => 404,
|
||||
error => 'Thread not found 🤷'
|
||||
)
|
||||
}
|
||||
|
||||
# Check for remarks or thread page number to make sure
|
||||
# remark->by_page_for did its job
|
||||
$self->stash(status => 404) unless $remarks->[0] || 1 >= $this_page;
|
||||
unless ((my $first_remark = $remarks->[0]) || 1 >= $this_page) {
|
||||
$self->stash(
|
||||
status => 404,
|
||||
error => 'Page not found 🕵️'
|
||||
)
|
||||
}
|
||||
|
||||
$self->render;
|
||||
}
|
||||
|
@ -81,14 +87,24 @@ sub by_page($self) {
|
|||
my $last_page = $self->thread->last_page;
|
||||
my $threads = $self->thread->by_page($this_page);
|
||||
|
||||
$self->stash(status => 404) unless $threads->[0];
|
||||
|
||||
if (my $first_thread = $threads->[0]) {
|
||||
$self->stash(
|
||||
threads => $threads,
|
||||
this_page => $this_page,
|
||||
last_page => $last_page,
|
||||
base_path => $base_path
|
||||
);
|
||||
)
|
||||
}
|
||||
else {
|
||||
$self->stash(
|
||||
threads => [],
|
||||
this_page => undef,
|
||||
last_page => undef,
|
||||
base_path => undef,
|
||||
status => 404,
|
||||
error => 'Page not found 🕵️'
|
||||
)
|
||||
}
|
||||
|
||||
$self->render;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ subtest 'View single thread', sub {
|
|||
->text_like(h2 => qr/Thread #1/);
|
||||
|
||||
$t->get_ok('/thread/single/65536')->status_is(404)
|
||||
->text_like(h2 => qr/Thread #/);
|
||||
->text_like(p => qr/Thread not found/);
|
||||
};
|
||||
|
||||
subtest 'Threads feed', sub {
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
% layout 'default';
|
||||
% title "Remark #$remark->{'id'}";
|
||||
% title my $remark_id = $remark->{'id'} ? "Remark #$remark_id" : '?';
|
||||
<h2 class="page-title"><%= title %></h2>
|
||||
<% if (my $remark_id = $remark->{'id'}) { =%>
|
||||
<main class="pager">
|
||||
<article class="post">
|
||||
<h4 class="post__title">
|
||||
<%= $remark->{'date'} %>
|
||||
<span class="post__id">#<%= $remark->{'id'} %></span>
|
||||
<span class="post__id">#<%= $remark_id %></span>
|
||||
</h4>
|
||||
<h5 class="post__author"><%= $remark->{'author'} %></h5>
|
||||
<div class="post__body">
|
||||
|
@ -31,3 +32,4 @@
|
|||
<% } =%>
|
||||
</article>
|
||||
</main>
|
||||
<% } =%>
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
% layout 'default';
|
||||
% title "Thread #$thread->{'id'}";
|
||||
% title my $thread_id = $thread->{'id'} ? "Thread #$thread_id" : '?';
|
||||
<h2 class="page-title"><%= title %></h2>
|
||||
<% if (my $thread_id = $thread->{'id'}) { =%>
|
||||
<main class="pager">
|
||||
<article class="post">
|
||||
<h3 class="post__title">
|
||||
<%= $thread->{'title'} %>
|
||||
<span class="post__id">#<%= $thread->{'id'} %></span>
|
||||
<span class="post__id">#<%= $thread_id %></span>
|
||||
</h3>
|
||||
<h4 class="post__date"><%= $thread->{'date'} %></h4>
|
||||
<h5 class="post__author"><%= $thread->{'author'} %></h5>
|
||||
|
@ -36,6 +37,7 @@
|
|||
<% } =%>
|
||||
</article>
|
||||
</main>
|
||||
<% } =%>
|
||||
<% if (my $first_remark = $remarks->[0]) { =%>
|
||||
<section class="pager" id="remarks">
|
||||
<h3 class="pager__title">Remarks</h3>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
% layout 'default';
|
||||
% title 'Threads List';
|
||||
<h2 class="page-title"><%= title %></h2>
|
||||
<% if (my $first_thread = $threads->[0]) { =%>
|
||||
<main class="pager">
|
||||
<% for my $thread (@{$threads}) { =%>
|
||||
<article class="post">
|
||||
|
@ -36,5 +37,6 @@
|
|||
<nav class="pager__nav">
|
||||
<%= pagination $this_page, $last_page, ($base_path . '/{page}') %>
|
||||
</nav>
|
||||
<% } =%>
|
||||
<% } =%>
|
||||
</main>
|
||||
<% } =%>
|
||||
|
|
Loading…
Reference in a new issue