From d313ca7fc1113e0e4a66415a000de27d8e5a3e81 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Thu, 24 Aug 2023 21:26:00 +0200 Subject: resolve unknown/ambiguous stop into list of stops --- lib/Travelynx/Controller/Traveling.pm | 48 ++++++++++++++++++++++++++++++----- lib/Travelynx/Helper/IRIS.pm | 10 +++++--- 2 files changed, 47 insertions(+), 11 deletions(-) (limited to 'lib/Travelynx') diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm index 86f85d8..251bc15 100755 --- a/lib/Travelynx/Controller/Traveling.pm +++ b/lib/Travelynx/Controller/Traveling.pm @@ -1074,20 +1074,54 @@ sub station { )->catch( sub { my ( $err, $status ) = @_; - if ($status) { + if ( $status and $status->{suggestions} ) { $self->render( - 'landingpage', - with_autocomplete => 1, - with_geolocation => 1, - error => $status->{errstr}, - status => 400, + 'disambiguation', + suggestions => $status->{suggestions}, + status => 300, ); } + elsif ( $use_hafas and $status and $status->errcode eq 'LOCATION' ) + { + $status->similar_stops_p->then( + sub { + my @suggestions = @_; + if ( @suggestions == 1 ) { + $self->redirect_to( + '/s/' . $suggestions[0]->{id} . '?hafas=1' ); + } + else { + $self->render( + 'disambiguation', + suggestions => [ + map { + { + name => $_->{name}, + eva => $_->{id} + } + } @suggestions + ], + status => 300, + ); + } + } + )->catch( + sub { + my ($err2) = @_; + $self->render( + 'exception', + exception => + "StopFinder threw '$err2' when handling '$err'", + status => 502 + ); + } + )->wait; + } else { $self->render( 'exception', exception => $err, - status => 500 + status => 502 ); } } diff --git a/lib/Travelynx/Helper/IRIS.pm b/lib/Travelynx/Helper/IRIS.pm index 4c286cb..a529e28 100644 --- a/lib/Travelynx/Helper/IRIS.pm +++ b/lib/Travelynx/Helper/IRIS.pm @@ -153,10 +153,12 @@ sub get_departures_p { return Mojo::Promise->reject( 'ambiguous station name', { - results => [], - errstr => - "Mehrdeutiger Stationsname: '$station'. Mögliche Eingaben: " - . join( q{, }, map { $_->[1] } @station_matches ), + results => [], + errstr => "Mehrdeutiger Stationsname: '$station'", + suggestions => [ + map { { name => $_->[1], eva => $_->[2] } } + @station_matches + ], } ); } -- cgit v1.2.3