HAFAS: Error handling, perltidy
This commit is contained in:
parent
56c275875c
commit
adaf65dc63
1 changed files with 55 additions and 28 deletions
|
@ -15,10 +15,9 @@ sub new {
|
|||
|
||||
my $version = $opt{version};
|
||||
|
||||
$opt{header} = {
|
||||
'User-Agent' =>
|
||||
"travelynx/${version} +https://finalrewind.org/projects/travelynx"
|
||||
};
|
||||
$opt{header}
|
||||
= { 'User-Agent' =>
|
||||
"travelynx/${version} +https://finalrewind.org/projects/travelynx" };
|
||||
|
||||
return bless( \%opt, $class );
|
||||
}
|
||||
|
@ -38,11 +37,17 @@ sub get_polyline_p {
|
|||
return $promise;
|
||||
}
|
||||
|
||||
$self->{user_agent}->request_timeout(5)->get_p(
|
||||
$url => $self->{header}
|
||||
)->then(
|
||||
$self->{user_agent}->request_timeout(5)->get_p( $url => $self->{header} )
|
||||
->then(
|
||||
sub {
|
||||
my ($tx) = @_;
|
||||
|
||||
if ( my $err = $tx->error ) {
|
||||
$promise->reject(
|
||||
"GET $url returned HTTP $err->{code} $err->{message}");
|
||||
return;
|
||||
}
|
||||
|
||||
my $body = decode( 'utf-8', $tx->res->body );
|
||||
my $json = JSON->new->decode($body);
|
||||
my @station_list;
|
||||
|
@ -55,8 +60,7 @@ sub get_polyline_p {
|
|||
and $feature->{properties}{type} eq 'stop' )
|
||||
{
|
||||
push( @{$coord}, $feature->{properties}{id} );
|
||||
push( @station_list,
|
||||
$feature->{properties}{name} );
|
||||
push( @station_list, $feature->{properties}{name} );
|
||||
}
|
||||
push( @coordinate_list, $coord );
|
||||
}
|
||||
|
@ -161,9 +165,17 @@ sub get_rest_p {
|
|||
return $promise;
|
||||
}
|
||||
|
||||
$self->{user_agent}->request_timeout(5)->get_p($url => $self->{header})->then(
|
||||
$self->{user_agent}->request_timeout(5)->get_p( $url => $self->{header} )
|
||||
->then(
|
||||
sub {
|
||||
my ($tx) = @_;
|
||||
|
||||
if ( my $err = $tx->error ) {
|
||||
$promise->reject(
|
||||
"GET $url returned HTTP $err->{code} $err->{message}");
|
||||
return;
|
||||
}
|
||||
|
||||
my $json = JSON->new->decode( $tx->res->body );
|
||||
$cache->freeze( $url, $json );
|
||||
$promise->resolve($json);
|
||||
|
@ -189,9 +201,17 @@ sub get_json_p {
|
|||
return $promise;
|
||||
}
|
||||
|
||||
$self->{user_agent}->request_timeout(5)->get_p($url => $self->{header})->then(
|
||||
$self->{user_agent}->request_timeout(5)->get_p( $url => $self->{header} )
|
||||
->then(
|
||||
sub {
|
||||
my ($tx) = @_;
|
||||
|
||||
if ( my $err = $tx->error ) {
|
||||
$promise->reject(
|
||||
"GET $url returned HTTP $err->{code} $err->{message}");
|
||||
return;
|
||||
}
|
||||
|
||||
my $body = decode( 'ISO-8859-15', $tx->res->body );
|
||||
|
||||
$body =~ s{^TSLs[.]sls = }{};
|
||||
|
@ -223,9 +243,17 @@ sub get_xml_p {
|
|||
return $promise;
|
||||
}
|
||||
|
||||
$self->{user_agent}->request_timeout(5)->get_p($url => $self->{header})->then(
|
||||
$self->{user_agent}->request_timeout(5)->get_p( $url => $self->{header} )
|
||||
->then(
|
||||
sub {
|
||||
my ($tx) = @_;
|
||||
|
||||
if ( my $err = $tx->error ) {
|
||||
$promise->reject(
|
||||
"GET $url returned HTTP $err->{code} $err->{message}");
|
||||
return;
|
||||
}
|
||||
|
||||
my $body = decode( 'ISO-8859-15', $tx->res->body );
|
||||
my $tree;
|
||||
|
||||
|
@ -258,8 +286,7 @@ sub get_xml_p {
|
|||
};
|
||||
}
|
||||
|
||||
for my $message ( $tree->findnodes('/Journey/HIMMessage') )
|
||||
{
|
||||
for my $message ( $tree->findnodes('/Journey/HIMMessage') ) {
|
||||
my $header = $message->getAttribute('header');
|
||||
my $lead = $message->getAttribute('lead');
|
||||
my $display = $message->getAttribute('display');
|
||||
|
|
Loading…
Reference in a new issue