summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2009-04-05 18:19:28 +0200
committerfranck cuny <franck@lumberjaph.net>2009-04-05 18:19:28 +0200
commit1e377af0527881dd4715cdaae40d8e4e0500bebd (patch)
tree3631fb4c9b1ef637d1e04e1a9f54cd6d1a2759ab /lib
parentrmeove connect info, in config file now (diff)
downloadintention-cloud-1e377af0527881dd4715cdaae40d8e4e0500bebd.tar.gz
check for error
Diffstat (limited to 'lib')
-rw-r--r--lib/intentioncloud/Model/Search.pm25
1 files changed, 15 insertions, 10 deletions
diff --git a/lib/intentioncloud/Model/Search.pm b/lib/intentioncloud/Model/Search.pm
index 5a27b2b..d0361db 100644
--- a/lib/intentioncloud/Model/Search.pm
+++ b/lib/intentioncloud/Model/Search.pm
@@ -12,7 +12,7 @@ sub search {
     my $search = $c->req->params->{ q } . " ";
     $c->stash( query => $search, dt => DateTime->now );
 
-    $c->stash(cloud_permalink => $c->stash->{dt}->ymd( '/' ) . '/'
+    $c->stash(cloud_permalink => $c->stash->{ dt }->ymd( '/' ) . '/'
             . $c->req->params->{ engine } . '/'
             . uri_escape( $c->req->params->{ q } ) );
     my $cloud = $c->model( 'DB::Search' )
@@ -35,16 +35,21 @@ sub google_search {
     my $suggest = WebService::Google::Suggest->new();
 
     my $suggests = 0;
-    foreach ( $suggest->complete( $search ) ) {
-        $suggests++;
-        if ( $_->{ results } > 0 ) {
-            $cloud->add( $_->{ query }, 'blah', $_->{ results } );
+    eval {
+        foreach ( $suggest->complete( $search ) )
+        {
+            $suggests++;
+            if ( $_->{ results } > 0 ) {
+                $cloud->add( $_->{ query }, 'blah', $_->{ results } );
+            }
         }
-    }
-    if ( $suggests ) {
-        $c->stash( cloud => $cloud->html_and_css() );
-    } else {
+    };
+    if ( $@ ) {
+        $c->stash( no_suggest => "the clouds seems broken" );
+    } elsif ( !$suggests ) {
         $c->stash( no_suggest => "no suggestions :(" );
+    } else {
+        $c->stash( cloud => $cloud->html_and_css() );
     }
 }
 
@@ -54,7 +59,7 @@ sub save_search {
     $c->model( 'DB::Search' )->create(
         {   engine       => $c->req->params->{ engine },
             cloud        => $c->stash->{ cloud },
-            date_created => $c->stash->{dt},
+            date_created => $c->stash->{ dt },
             query        => $c->req->params->{ q },
             permalink    => $c->stash->{ cloud_permalink },
         }