summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2025-01-20 19:00:19 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2025-01-20 19:00:19 +0100
commitfd9bb806d8863678920e4252c1411b17a19520f9 (patch)
tree00fd57c37f0d59750d5eb56c7059ed9fbc0d8727
parent18de123e20f2d7499338272f33e1fbe37227251d (diff)
dbris: Filter out unsupported MOTs rather than passing them to the backend
-rwxr-xr-xbin/dbris19
1 files changed, 18 insertions, 1 deletions
diff --git a/bin/dbris b/bin/dbris
index 6cc6ee9..034ad01 100755
--- a/bin/dbris
+++ b/bin/dbris
@@ -24,6 +24,8 @@ my $show_full_route;
my $cache;
my @output;
+my %known_mot = map { $_ => 1 }
+ (qw(ICE EC_IC IR REGIONAL SBAHN BUS SCHIFF UBAHN TRAM ANRUFPFLICHTIG));
binmode( STDOUT, ':encoding(utf-8)' );
for my $arg (@ARGV) {
@@ -158,7 +160,22 @@ if ( $date or $time ) {
}
if ($mots) {
- $opt{modes_of_transit} = [ split( qr{, *}, $mots ) ];
+
+ # Passing unknown MOTs to the backend results in HTTP 422 Unprocessable Entity
+ my @mots = split( qr{, *}, $mots );
+ my $found_unknown;
+ for my $mot (@mots) {
+ if ( not $known_mot{$mot} ) {
+ $found_unknown = 1;
+ say STDERR
+"-m / --modes-of-transit: skipping unknown mode of transit '$mot'";
+ }
+ }
+ if ($found_unknown) {
+ say STDERR 'supported modes of transit are: '
+ . join( q{, }, sort keys %known_mot );
+ }
+ $opt{modes_of_transit} = [ grep { $known_mot{$_} } @mots ];
}
if ($discounts) {