diff options
author | Daniel Friesel <derf@finalrewind.org> | 2022-08-17 21:51:24 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2022-08-17 21:51:24 +0200 |
commit | 0e14df21d29053bef4a3a9967edec67b35d10a34 (patch) | |
tree | c579b6f100dd68c53758d6d765dcf4f5d7f410a5 | |
parent | 5bf1318cf5980511301ac542f5c0096dfccb0dbd (diff) |
traewelling: more detailed error messages
-rwxr-xr-x | lib/Travelynx.pm | 8 | ||||
-rw-r--r-- | lib/Travelynx/Helper/Traewelling.pm | 46 |
2 files changed, 35 insertions, 19 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index 3612fd0..6c2dd50 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -13,11 +13,11 @@ use Cache::File; use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64); use DateTime; use DateTime::Format::Strptime; -use Encode qw(decode encode); +use Encode qw(decode encode); use File::Slurp qw(read_file); use JSON; use List::Util; -use List::UtilsBy qw(uniq_by); +use List::UtilsBy qw(uniq_by); use List::MoreUtils qw(first_index); use Travel::Status::DE::DBWagenreihung; use Travel::Status::DE::IRIS::Stations; @@ -1927,7 +1927,9 @@ sub startup { $self->log->debug("... already handled"); return; } - $self->log->debug("... checked in"); + $self->log->debug( +"... checked in : $traewelling->{dep_name} $traewelling->{dep_eva} -> $traewelling->{arr_name} $traewelling->{arr_eva}" + ); my $user_status = $self->get_user_status($uid); if ( $user_status->{checked_in} ) { $self->log->debug( diff --git a/lib/Travelynx/Helper/Traewelling.pm b/lib/Travelynx/Helper/Traewelling.pm index 4d6c180..662aeff 100644 --- a/lib/Travelynx/Helper/Traewelling.pm +++ b/lib/Travelynx/Helper/Traewelling.pm @@ -81,7 +81,8 @@ sub get_status_p { sub { my ($tx) = @_; if ( my $err = $tx->error ) { - my $err_msg = "HTTP $err->{code} $err->{message}"; + my $err_msg + = "v1/user/${username}/statuses: HTTP $err->{code} $err->{message}"; $promise->reject($err_msg); return; } @@ -102,6 +103,11 @@ sub get_status_p { my $arr_eva = $status->{train}{destination}{evaIdentifier}; + my $dep_ds100 + = $status->{train}{origin}{rilIdentifier}; + my $arr_ds100 + = $status->{train}{destination}{rilIdentifier}; + my $dep_name = $status->{train}{origin}{name}; my $arr_name @@ -117,9 +123,11 @@ sub get_status_p { checkin => $checkin_at, dep_dt => $dep_dt, dep_eva => $dep_eva, + dep_ds100 => $dep_ds100, dep_name => $dep_name, arr_dt => $arr_dt, arr_eva => $arr_eva, + arr_ds100 => $arr_ds100, arr_name => $arr_name, train_type => $train_type, line => $linename, @@ -130,7 +138,7 @@ sub get_status_p { return; } else { - $promise->reject("unknown error"); + $promise->reject("v1/${username}/statuses: unknown error"); return; } } @@ -138,7 +146,7 @@ sub get_status_p { )->catch( sub { my ($err) = @_; - $promise->reject($err); + $promise->reject("v1/${username}/statuses: $err"); return; } )->wait; @@ -161,8 +169,7 @@ sub get_user_p { sub { my ($tx) = @_; if ( my $err = $tx->error ) { - my $err_msg - = "HTTP $err->{code} $err->{message} bei Abfrage der Nutzerdaten"; + my $err_msg = "v0/getuser: HTTP $err->{code} $err->{message}"; $promise->reject($err_msg); return; } @@ -181,7 +188,7 @@ sub get_user_p { )->catch( sub { my ($err) = @_; - $promise->reject("$err bei Abfrage der Nutzerdaten"); + $promise->reject("v0/getuser: $err"); return; } )->wait; @@ -213,7 +220,8 @@ sub login_p { sub { my ($tx) = @_; if ( my $err = $tx->error ) { - my $err_msg = "HTTP $err->{code} $err->{message} bei Login"; + my $err_msg + = "v0/auth/login: HTTP $err->{code} $err->{message}"; $promise->reject($err_msg); return; } @@ -251,13 +259,13 @@ sub login_p { token => $token )->finally( sub { - $promise->reject($err); + $promise->reject("v0/auth/login: $err"); return; } ); } else { - $promise->reject($err); + $promise->reject("v0/auth/login: $err"); } return; } @@ -291,7 +299,8 @@ sub logout_p { sub { my ($tx) = @_; if ( my $err = $tx->error ) { - my $err_msg = "HTTP $err->{code} $err->{message}"; + my $err_msg + = "v0/auth/logout: HTTP $err->{code} $err->{message}"; $promise->reject($err_msg); return; } @@ -303,7 +312,7 @@ sub logout_p { )->catch( sub { my ($err) = @_; - $promise->reject($err); + $promise->reject("v0/auth/logout: $err"); return; } )->wait; @@ -346,6 +355,9 @@ sub checkin { $request->{body} = $opt{user_data}{comment}; } + my $debug_prefix + = "v0/trains/checkin('$request->{lineName}' $request->{tripID} $request->{start} -> $request->{destination})"; + $self->{user_agent}->request_timeout(20) ->post_p( "https://traewelling.de/api/v0/trains/checkin" => $header => json => @@ -371,15 +383,17 @@ sub checkin { and $err->{code} != 406 and $err->{code} != 401 ) { - $self->{log}->warn("Traewelling checkin error: $err_msg"); + $self->{log} + ->warn("Traewelling $debug_prefix error: $err_msg"); } else { - $self->{log}->debug("Traewelling checkin error: $err_msg"); + $self->{log} + ->debug("Traewelling $debug_prefix error: $err_msg"); } $self->{model}->log( uid => $opt{uid}, message => -"Konnte $opt{train_type} $opt{train_no} nicht übertragen: $err_msg", +"Konnte $opt{train_type} $opt{train_no} nicht übertragen: $debug_prefix returned $err_msg", is_error => 1 ); return; @@ -405,11 +419,11 @@ sub checkin { )->catch( sub { my ($err) = @_; - $self->{log}->debug("... error: $err"); + $self->{log}->debug("... $debug_prefix error: $err"); $self->{model}->log( uid => $opt{uid}, message => -"Konnte $opt{train_type} $opt{train_no} nicht übertragen: $err", +"Konnte $opt{train_type} $opt{train_no} nicht übertragen: $debug_prefix returned $err", is_error => 1 ); } |