summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2023-08-24 21:26:00 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2023-08-24 21:26:00 +0200
commitd313ca7fc1113e0e4a66415a000de27d8e5a3e81 (patch)
treeab1336ac1f6b21ad95bc7956a337983542949334 /lib
parentd23283329df18171fbc0f965d42c9af37c175084 (diff)
resolve unknown/ambiguous stop into list of stops
Diffstat (limited to 'lib')
-rwxr-xr-xlib/Travelynx/Controller/Traveling.pm48
-rw-r--r--lib/Travelynx/Helper/IRIS.pm10
2 files changed, 47 insertions, 11 deletions
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
+ ],
}
);
}