traewelling: more detailed error messages
This commit is contained in:
parent
5bf1318cf5
commit
0e14df21d2
2 changed files with 35 additions and 19 deletions
|
@ -13,11 +13,11 @@ use Cache::File;
|
||||||
use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64);
|
use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64);
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use DateTime::Format::Strptime;
|
use DateTime::Format::Strptime;
|
||||||
use Encode qw(decode encode);
|
use Encode qw(decode encode);
|
||||||
use File::Slurp qw(read_file);
|
use File::Slurp qw(read_file);
|
||||||
use JSON;
|
use JSON;
|
||||||
use List::Util;
|
use List::Util;
|
||||||
use List::UtilsBy qw(uniq_by);
|
use List::UtilsBy qw(uniq_by);
|
||||||
use List::MoreUtils qw(first_index);
|
use List::MoreUtils qw(first_index);
|
||||||
use Travel::Status::DE::DBWagenreihung;
|
use Travel::Status::DE::DBWagenreihung;
|
||||||
use Travel::Status::DE::IRIS::Stations;
|
use Travel::Status::DE::IRIS::Stations;
|
||||||
|
@ -1927,7 +1927,9 @@ sub startup {
|
||||||
$self->log->debug("... already handled");
|
$self->log->debug("... already handled");
|
||||||
return;
|
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);
|
my $user_status = $self->get_user_status($uid);
|
||||||
if ( $user_status->{checked_in} ) {
|
if ( $user_status->{checked_in} ) {
|
||||||
$self->log->debug(
|
$self->log->debug(
|
||||||
|
|
|
@ -81,7 +81,8 @@ sub get_status_p {
|
||||||
sub {
|
sub {
|
||||||
my ($tx) = @_;
|
my ($tx) = @_;
|
||||||
if ( my $err = $tx->error ) {
|
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);
|
$promise->reject($err_msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -102,6 +103,11 @@ sub get_status_p {
|
||||||
my $arr_eva
|
my $arr_eva
|
||||||
= $status->{train}{destination}{evaIdentifier};
|
= $status->{train}{destination}{evaIdentifier};
|
||||||
|
|
||||||
|
my $dep_ds100
|
||||||
|
= $status->{train}{origin}{rilIdentifier};
|
||||||
|
my $arr_ds100
|
||||||
|
= $status->{train}{destination}{rilIdentifier};
|
||||||
|
|
||||||
my $dep_name
|
my $dep_name
|
||||||
= $status->{train}{origin}{name};
|
= $status->{train}{origin}{name};
|
||||||
my $arr_name
|
my $arr_name
|
||||||
|
@ -117,9 +123,11 @@ sub get_status_p {
|
||||||
checkin => $checkin_at,
|
checkin => $checkin_at,
|
||||||
dep_dt => $dep_dt,
|
dep_dt => $dep_dt,
|
||||||
dep_eva => $dep_eva,
|
dep_eva => $dep_eva,
|
||||||
|
dep_ds100 => $dep_ds100,
|
||||||
dep_name => $dep_name,
|
dep_name => $dep_name,
|
||||||
arr_dt => $arr_dt,
|
arr_dt => $arr_dt,
|
||||||
arr_eva => $arr_eva,
|
arr_eva => $arr_eva,
|
||||||
|
arr_ds100 => $arr_ds100,
|
||||||
arr_name => $arr_name,
|
arr_name => $arr_name,
|
||||||
train_type => $train_type,
|
train_type => $train_type,
|
||||||
line => $linename,
|
line => $linename,
|
||||||
|
@ -130,7 +138,7 @@ sub get_status_p {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$promise->reject("unknown error");
|
$promise->reject("v1/${username}/statuses: unknown error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,7 +146,7 @@ sub get_status_p {
|
||||||
)->catch(
|
)->catch(
|
||||||
sub {
|
sub {
|
||||||
my ($err) = @_;
|
my ($err) = @_;
|
||||||
$promise->reject($err);
|
$promise->reject("v1/${username}/statuses: $err");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
)->wait;
|
)->wait;
|
||||||
|
@ -161,8 +169,7 @@ sub get_user_p {
|
||||||
sub {
|
sub {
|
||||||
my ($tx) = @_;
|
my ($tx) = @_;
|
||||||
if ( my $err = $tx->error ) {
|
if ( my $err = $tx->error ) {
|
||||||
my $err_msg
|
my $err_msg = "v0/getuser: HTTP $err->{code} $err->{message}";
|
||||||
= "HTTP $err->{code} $err->{message} bei Abfrage der Nutzerdaten";
|
|
||||||
$promise->reject($err_msg);
|
$promise->reject($err_msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -181,7 +188,7 @@ sub get_user_p {
|
||||||
)->catch(
|
)->catch(
|
||||||
sub {
|
sub {
|
||||||
my ($err) = @_;
|
my ($err) = @_;
|
||||||
$promise->reject("$err bei Abfrage der Nutzerdaten");
|
$promise->reject("v0/getuser: $err");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
)->wait;
|
)->wait;
|
||||||
|
@ -213,7 +220,8 @@ sub login_p {
|
||||||
sub {
|
sub {
|
||||||
my ($tx) = @_;
|
my ($tx) = @_;
|
||||||
if ( my $err = $tx->error ) {
|
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);
|
$promise->reject($err_msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -251,13 +259,13 @@ sub login_p {
|
||||||
token => $token
|
token => $token
|
||||||
)->finally(
|
)->finally(
|
||||||
sub {
|
sub {
|
||||||
$promise->reject($err);
|
$promise->reject("v0/auth/login: $err");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$promise->reject($err);
|
$promise->reject("v0/auth/login: $err");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -291,7 +299,8 @@ sub logout_p {
|
||||||
sub {
|
sub {
|
||||||
my ($tx) = @_;
|
my ($tx) = @_;
|
||||||
if ( my $err = $tx->error ) {
|
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);
|
$promise->reject($err_msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -303,7 +312,7 @@ sub logout_p {
|
||||||
)->catch(
|
)->catch(
|
||||||
sub {
|
sub {
|
||||||
my ($err) = @_;
|
my ($err) = @_;
|
||||||
$promise->reject($err);
|
$promise->reject("v0/auth/logout: $err");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
)->wait;
|
)->wait;
|
||||||
|
@ -346,6 +355,9 @@ sub checkin {
|
||||||
$request->{body} = $opt{user_data}{comment};
|
$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)
|
$self->{user_agent}->request_timeout(20)
|
||||||
->post_p(
|
->post_p(
|
||||||
"https://traewelling.de/api/v0/trains/checkin" => $header => json =>
|
"https://traewelling.de/api/v0/trains/checkin" => $header => json =>
|
||||||
|
@ -371,15 +383,17 @@ sub checkin {
|
||||||
and $err->{code} != 406
|
and $err->{code} != 406
|
||||||
and $err->{code} != 401 )
|
and $err->{code} != 401 )
|
||||||
{
|
{
|
||||||
$self->{log}->warn("Traewelling checkin error: $err_msg");
|
$self->{log}
|
||||||
|
->warn("Traewelling $debug_prefix error: $err_msg");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$self->{log}->debug("Traewelling checkin error: $err_msg");
|
$self->{log}
|
||||||
|
->debug("Traewelling $debug_prefix error: $err_msg");
|
||||||
}
|
}
|
||||||
$self->{model}->log(
|
$self->{model}->log(
|
||||||
uid => $opt{uid},
|
uid => $opt{uid},
|
||||||
message =>
|
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
|
is_error => 1
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
|
@ -405,11 +419,11 @@ sub checkin {
|
||||||
)->catch(
|
)->catch(
|
||||||
sub {
|
sub {
|
||||||
my ($err) = @_;
|
my ($err) = @_;
|
||||||
$self->{log}->debug("... error: $err");
|
$self->{log}->debug("... $debug_prefix error: $err");
|
||||||
$self->{model}->log(
|
$self->{model}->log(
|
||||||
uid => $opt{uid},
|
uid => $opt{uid},
|
||||||
message =>
|
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
|
is_error => 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue