diff options
author | Daniel Friesel <derf@finalrewind.org> | 2014-10-19 21:04:08 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2014-10-19 21:04:08 +0200 |
commit | be21dec79365be950f9bc8cb78baa826e3e0f704 (patch) | |
tree | 30c8f245ee98cfea3f594d965e7c4d985012a562 /index.pl | |
parent | c73b20e6393cb56d295bff560a4971f391f0b2d4 (diff) |
json: show list of candidates in case of an error
Diffstat (limited to 'index.pl')
-rw-r--r-- | index.pl | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -79,6 +79,28 @@ sub handle_request { my @departures; my @results = get_results_for( $backend, $station ); + if ( not @results and $template eq 'json' ) { + if ( $backend eq 'iris' ) { + my @candidates = map { { code => $_->[0], name => $_->[1] } } + Travel::Status::DE::IRIS::Stations::get_station($station); + $self->render( + json => { + version => $VERSION, + error => 'ambiguous station code/name', + candidates => \@candidates, + } + ); + return; + } + $self->render( + json => { + version => $VERSION, + error => 'unknown station code/name', + } + ); + return; + } + if ( not @results ) { if ( $backend eq 'iris' ) { my @candidates = map { [ "$_->[1] ($_->[0])", $_->[0] ] } @@ -89,6 +111,7 @@ sub handle_request { stationlist => \@candidates, hide_opts => 0 ); + return; } } $self->render( |