diff options
author | Daniel Friesel <derf@finalrewind.org> | 2011-06-28 00:53:55 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2011-06-28 00:53:55 +0200 |
commit | 1e036e94b7b5500d8c1630548398980735ad9110 (patch) | |
tree | 2d9bc3f2417079859d3e96adc2f1bd9cf63b6acd /lib/Travel/Status/DE/DeutscheBahn.pm | |
parent | c7579bf432c6ec7bab2e502725ce2e3c1f16eccb (diff) |
DeutscheBahn.pm: Proper HTTP error handling
Diffstat (limited to 'lib/Travel/Status/DE/DeutscheBahn.pm')
-rw-r--r-- | lib/Travel/Status/DE/DeutscheBahn.pm | 14 |
1 files changed, 11 insertions, 3 deletions
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}, |