api/import: More helpful errors, fix "lax" support
This commit is contained in:
parent
ae21896982
commit
934a9ac21a
2 changed files with 31 additions and 10 deletions
|
@ -350,20 +350,25 @@ sub startup {
|
|||
my @unknown_stations;
|
||||
for my $station ( @{ $opt{route} } ) {
|
||||
my $station_info = get_station($station);
|
||||
if ( not $station_info ) {
|
||||
if ($station_info) {
|
||||
push( @route, [ $station_info->[1], {}, undef ] );
|
||||
}
|
||||
else {
|
||||
push( @route, [ $station, {}, undef ] );
|
||||
push( @unknown_stations, $station );
|
||||
}
|
||||
push( @route, [ $station_info->[1], {}, undef ] );
|
||||
}
|
||||
|
||||
if ( @unknown_stations == 1 ) {
|
||||
return ( undef,
|
||||
"Unbekannter Unterwegshalt: $unknown_stations[0]" );
|
||||
}
|
||||
elsif (@unknown_stations) {
|
||||
return ( undef,
|
||||
'Unbekannte Unterwegshalte: '
|
||||
. join( ', ', @unknown_stations ) );
|
||||
if ( not $opt{lax} ) {
|
||||
if ( @unknown_stations == 1 ) {
|
||||
return ( undef,
|
||||
"Unbekannter Unterwegshalt: $unknown_stations[0]" );
|
||||
}
|
||||
elsif (@unknown_stations) {
|
||||
return ( undef,
|
||||
'Unbekannte Unterwegshalte: '
|
||||
. join( ', ', @unknown_stations ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -389,6 +389,21 @@ sub import_v1 {
|
|||
my %opt;
|
||||
|
||||
eval {
|
||||
|
||||
if ( not $payload->{fromStation}{name}
|
||||
or not $payload->{toStation}{name} )
|
||||
{
|
||||
die("Missing fromStation/toStation name\n");
|
||||
}
|
||||
if ( not $payload->{train}{type} or not $payload->{train}{no} ) {
|
||||
die("Missing train data\n");
|
||||
}
|
||||
if ( not $payload->{fromStation}{scheduledTime}
|
||||
or not $payload->{toStation}{scheduledTime} )
|
||||
{
|
||||
die("Missing fromStation/toStation scheduledTime\n");
|
||||
}
|
||||
|
||||
%opt = (
|
||||
uid => $uid,
|
||||
train_type => sanitize( q{}, $payload->{train}{type} ),
|
||||
|
@ -412,6 +427,7 @@ sub import_v1 {
|
|||
// $payload->{toStation}{scheduledTime}
|
||||
),
|
||||
comment => sanitize( q{}, $payload->{comment} ),
|
||||
lax => $payload->{lax} ? 1 : 0,
|
||||
);
|
||||
|
||||
if ( $payload->{route} and ref( $payload->{route} ) eq 'ARRAY' ) {
|
||||
|
|
Loading…
Reference in a new issue