travel API: more helpful errors on invalid input
This commit is contained in:
parent
bd372d57e2
commit
11a2e94a04
2 changed files with 37 additions and 6 deletions
|
@ -221,7 +221,7 @@ sub travel_v1 {
|
|||
}
|
||||
|
||||
my $token = $self->get_api_token($uid);
|
||||
if ( $api_token ne $token->{'travel'} ) {
|
||||
if ( not $token->{'travel'} or $api_token ne $token->{'travel'} ) {
|
||||
$self->render(
|
||||
json => {
|
||||
success => \0,
|
||||
|
@ -240,6 +240,7 @@ sub travel_v1 {
|
|||
success => \0,
|
||||
deprecated => \0,
|
||||
error => 'Missing or invalid action',
|
||||
status => $self->get_user_status_json_v1($uid)
|
||||
},
|
||||
);
|
||||
return;
|
||||
|
@ -250,6 +251,25 @@ sub travel_v1 {
|
|||
my $to_station = sanitize( q{}, $payload->{toStation} );
|
||||
my $train_id;
|
||||
|
||||
if (
|
||||
not(
|
||||
$from_station
|
||||
and ( ( $payload->{train}{type} and $payload->{train}{no} )
|
||||
or $payload->{train}{id} )
|
||||
)
|
||||
)
|
||||
{
|
||||
$self->render(
|
||||
json => {
|
||||
success => \0,
|
||||
deprecated => \0,
|
||||
error => 'Missing fromStation or train data',
|
||||
status => $self->get_user_status_json_v1($uid)
|
||||
},
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( exists $payload->{train}{id} ) {
|
||||
$train_id = sanitize( 0, $payload->{train}{id} );
|
||||
}
|
||||
|
@ -277,9 +297,8 @@ sub travel_v1 {
|
|||
json => {
|
||||
success => \0,
|
||||
deprecated => \0,
|
||||
error => 'Fehler am Abfahrtsbahnhof: '
|
||||
. $status->{errstr},
|
||||
status => $self->get_user_status_json_v1($uid)
|
||||
error => 'Zug nicht gefunden',
|
||||
status => $self->get_user_status_json_v1($uid)
|
||||
}
|
||||
);
|
||||
return;
|
||||
|
@ -319,6 +338,18 @@ sub travel_v1 {
|
|||
elsif ( $payload->{action} eq 'checkout' ) {
|
||||
my $to_station = sanitize( q{}, $payload->{toStation} );
|
||||
|
||||
if ( not $to_station ) {
|
||||
$self->render(
|
||||
json => {
|
||||
success => \0,
|
||||
deprecated => \0,
|
||||
error => 'Missing toStation',
|
||||
status => $self->get_user_status_json_v1($uid)
|
||||
},
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $payload->{comment} ) {
|
||||
$self->update_in_transit_comment(
|
||||
sanitize( q{}, $payload->{comment} ), $uid );
|
||||
|
|
|
@ -78,7 +78,7 @@
|
|||
Der Checkout erfolgt unabhängig davon, ob der vorherige Zug an dieser
|
||||
Station verkehrt oder nicht. Falls nach einem Checkin ohne Zielwahl
|
||||
innerhalb von 48 Stunden kein Zielbahnhof nachgetragen wird, wird der
|
||||
CHeckin automatisch rückgängig gemacht.
|
||||
Checkin automatisch rückgängig gemacht.
|
||||
</p>
|
||||
<p style="font-family: Monospace;">
|
||||
curl -X POST -H "Content-Type: application/json" -d '{"token":"<%= $uid %>-<%= $token->{travel} // 'TOKEN' %>"}' <%= $api_root %>/travel
|
||||
|
@ -132,7 +132,7 @@
|
|||
"success" : false,<br/>
|
||||
"deprecated" : true / false, (falls true: Diese API-Version wird irgendwann abgeschaltet, bitte auf eine neue umsteigen)<br/>
|
||||
"error" : "Begründung",<br/>
|
||||
"status" : { aktueller Nutzerstatus gemäß Status-API }<br/>
|
||||
"status" : { aktueller Nutzerstatus gemäß Status-API } (nur bei gültigem Token)<br/>
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue