Explorar el Código

Give the error pages the path and the message that their templates show

404.tx says which resource was not found, from $path, and nothing ever set
$path, so the page named nothing.  500.tx shows $message, which tPSGI sets
when a route dies, and which nothing else passes.  Under the lock on a
template's variables, both pages died rather than rendered.

Now generic_route() sets the path from the request, and leaves the message
as tPSGI set it, or undef.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
troglodyne-bot hace 3 días
padre
commit
a4ed87ba13
Se han modificado 2 ficheros con 14 adiciones y 0 borrados
  1. 5 0
      lib/TCMS.pm
  2. 9 0
      t/Trog-Routes-HTML-series-lifecycle.t

+ 5 - 0
lib/TCMS.pm

@@ -276,6 +276,11 @@ sub generic_route ( $rname, $code, $title, $query ) {
     $query->{route} //= $rname;
     $query->{title}    = $title;
     $query->{template} = "$rname.tx";
+
+    # What the error pages read: 404.tx the path that was not found, and
+    # 500.tx the message that tPSGI sets when a route dies.
+    $query->{path} = $query->{fullpath} // $query->{route};
+    $query->{message} //= undef;
     return Trog::Routes::HTML::index($query);
 }
 

+ 9 - 0
t/Trog-Routes-HTML-series-lifecycle.t

@@ -1700,6 +1700,15 @@ subtest 'the sitemap page' => sub {
     is( $code, 200, 'renders' ) or diag($err);
 };
 
+subtest 'the error pages' => sub {
+    require TCMS;
+    foreach my $code (qw{400 403 404 405 415 419 500 503}) {
+        my ( $got, $body, $err ) = render( anon( route => '/nowhere' ), sub ($query) { TCMS::generic_route( "/$code", $code, 'Some Error', $query ) } );
+        is( $got, $code, "the page for a $code renders" ) or diag($err);
+        like( $body, qr{No[ ]such[ ]resource[ ]/nowhere}, 'and names the path that is not there' ) if $code == 404;
+    }
+};
+
 subtest 'the tpsgi side effects stayed inert' => sub {
     cmp_ok( $TPSGI->{restarts},  '>', 0, 'post_save did try to signal a restart' );
     cmp_ok( $TPSGI->{callbacks}, '>', 0, 'and did queue post-close callbacks' );