summaryrefslogtreecommitdiff
path: root/cgi/index.pl
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-08-12 01:21:40 +0200
committerDaniel Friesel <derf@finalrewind.org>2011-08-12 01:21:40 +0200
commit4c0dc86a3fd165ae2fa2c48286056c9ea13a2352 (patch)
tree1b67e45b89bd1ad110fb805111c9f3297d6c8831 /cgi/index.pl
parent731a744d34b0ce1f670524a1b08d8d71c44288c7 (diff)
cgi: Error handling
Diffstat (limited to 'cgi/index.pl')
-rw-r--r--cgi/index.pl24
1 files changed, 15 insertions, 9 deletions
diff --git a/cgi/index.pl b/cgi/index.pl
index 3051f94..96dd488 100644
--- a/cgi/index.pl
+++ b/cgi/index.pl
@@ -9,20 +9,20 @@ sub get_results_for {
my ($station) = @_;
my $cache = Cache::File->new(
- cache_root => '/tmp/db-fake',
+ cache_root => '/tmp/db-fake',
default_expires => '900 sec'
);
my $results = $cache->thaw($station);
- if (not $results) {
- my $status = Travel::Status::DE::DeutscheBahn->new( station => $station
- );
- $results = [$status->results];
- $cache->freeze($station, $results);
+ if ( not $results ) {
+ my $status
+ = Travel::Status::DE::DeutscheBahn->new( station => $station );
+ $results = [ $status->results ];
+ $cache->freeze( $station, $results );
}
- return @{ $results };
+ return @{$results};
}
get '/' => sub {
@@ -43,8 +43,14 @@ get '/multi/:station' => sub {
filename => dist_file( 'db-fakedisplay', 'multi-lcd.html' ),
loop_context_vars => 1,
);
+ my @results = get_results_for($station);
+
+ if ( not @results ) {
+ $self->render( 'index', error => "Got no results for '$station'", );
+ return;
+ }
- for my $result ( get_results_for($station) ) {
+ for my $result (@results) {
push(
@params,
{
@@ -68,7 +74,7 @@ __DATA__
@@ index.html.ep
% title 'DB Fakedisplay';
-<% if (my $error = flash 'error' ) { %>
+<% if (my $error = stash 'error') { %>
Error: <%= $error %><br/>
<% } %>
<%= form_for index => begin %>