From 21db75aa35f08c86458481dacd06638c68f1318c Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 12 Feb 2023 18:02:31 +0100 Subject: handle_no_results: return HTTP 500 when called from an exception handler --- lib/DBInfoscreen/Controller/Stationboard.pm | 37 +++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'lib/DBInfoscreen/Controller/Stationboard.pm') diff --git a/lib/DBInfoscreen/Controller/Stationboard.pm b/lib/DBInfoscreen/Controller/Stationboard.pm index 05d4afb..317ed74 100644 --- a/lib/DBInfoscreen/Controller/Stationboard.pm +++ b/lib/DBInfoscreen/Controller/Stationboard.pm @@ -65,7 +65,7 @@ sub handle_no_results { error => $err, stationlist => \@candidates, hide_opts => 0, - status => 300, + status => $data->{status} // 300, ); return; } @@ -75,7 +75,8 @@ sub handle_no_results { $self->render( 'landingpage', error => ( $err // "Keine Abfahrten an '$station'" ), - hide_opts => 0 + hide_opts => 0, + status => $data->{status} // 500, ); return; } @@ -96,7 +97,7 @@ sub handle_no_results { 'landingpage', stationlist => \@candidates, hide_opts => 0, - status => 300, + status => $data->{status} // 300, ); return; } @@ -106,14 +107,16 @@ sub handle_no_results { 'landingpage', error => ( $errstr // "Keine Abfahrten an '$station'" ) . '. Das von DBF genutzte IRIS-Backend unterstützt im Regelfall nur innerdeutsche Zugfahrten.', - hide_opts => 0 + hide_opts => 0, + status => $data->{status} // 200, ); return; } $self->render( 'landingpage', error => ( $errstr // "Keine Abfahrten an '$station'" ), - hide_opts => 0 + hide_opts => 0, + status => $data->{status} // 404, ); return; } @@ -158,12 +161,13 @@ sub handle_no_results_json { $json = $self->render_to_string( json => $json ); $self->render( data => "$callback($json);", - format => 'json' + format => 'json', ); } else { $self->render( - json => $json, + json => $json, + status => $data->{status} // 300, ); } return; @@ -492,11 +496,24 @@ sub handle_request { sub { my ($err) = @_; if ( $template eq 'json' ) { - $self->handle_no_results_json( $station, { errstr => $err }, - $api_version ); + $self->handle_no_results_json( + $station, + { + errstr => $err, + status => 500 + }, + $api_version + ); return; } - $self->handle_no_results( $station, { errstr => $err }, $hafas ); + $self->handle_no_results( + $station, + { + errstr => $err, + status => 500 + }, + $hafas + ); return; } )->wait; -- cgit v1.2.3