From 1e036e94b7b5500d8c1630548398980735ad9110 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 28 Jun 2011 00:53:55 +0200 Subject: DeutscheBahn.pm: Proper HTTP error handling --- Changelog | 4 ++++ lib/Travel/Status/DE/DeutscheBahn.pm | 14 +++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Changelog b/Changelog index f045f79..211ddb2 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,7 @@ +git HEAD + + * Proper HTTP request error handling + Travel::Status::DE::DeutscheBahn 0.01 - Mon Jun 27 2011 * Initial release diff --git a/lib/Travel/Status/DE/DeutscheBahn.pm b/lib/Travel/Status/DE/DeutscheBahn.pm index 095a6eb..12450b2 100644 --- a/lib/Travel/Status/DE/DeutscheBahn.pm +++ b/lib/Travel/Status/DE/DeutscheBahn.pm @@ -19,6 +19,8 @@ sub new { my $ua = LWP::UserAgent->new(); + my $reply; + if ( not $conf{station} ) { confess('You need to specify a station'); } @@ -52,9 +54,15 @@ sub new { } } - $ref->{html} - = $ua->post( 'http://reiseauskunft.bahn.de/bin/bhftafel.exe/dn?rt=1', - $ref->{post} )->content(); + $reply = $ua->post( 'http://reiseauskunft.bahn.de/bin/bhftafel.exe/dn?rt=1', + $ref->{post} ); + + if ( $reply->is_error ) { + my $errstr = $reply->status_line(); + confess("Could not submit POST request: ${errstr}"); + } + + $ref->{html} = $reply->content(); $ref->{tree} = XML::LibXML->load_html( string => $ref->{html}, -- cgit v1.2.3