better error handling in google export, #12064
authormark <mark>
Sat, 30 Apr 2011 21:22:55 +0000 (21:22 +0000)
committermark <mark>
Sat, 30 Apr 2011 21:22:55 +0000 (21:22 +0000)
FS/FS/part_export/acct_google.pm
httemplate/edit/svc_acct.cgi

index c64d293..afc45db 100644 (file)
@@ -89,15 +89,18 @@ sub _export_unsuspend {
   );
 }
 
-sub captcha_url {
+sub auth_error {
   my $self = shift;
   my $google = $self->google_handle;
-  if (exists ($google->{'captcha_url'}) ) {
-    return 'http://www.google.com/accounts/'.$google->{'captcha_url'};
-  }
-  else {
-    return '';
+  if ( $google->{'error'} ) {
+    my $url = $google->{'captcha_url'} || '';
+    $url = "http://www.google.com/accounts/$url" if $url;
+    return { 'captcha_url' => $url,
+             'message'     => 
+               'Unable to connect to the Google API: '.$google->{'error'}.'.',
+           };
   }
+  return; #nothing on success
 }
 
 sub captcha_auth {
index 2eb4a8b..f2b8e0c 100755 (executable)
@@ -494,7 +494,15 @@ sub max {
 my $captcha_url;
 my ($export_google) = $part_svc->part_export('acct_google');
 if ( $export_google ) {
-  $captcha_url = $export_google->captcha_url || '';
+  my $error = $export_google->auth_error;
+  if ( $error ) {
+    if ( $error->{'captcha_url'} ) {
+      $captcha_url = $error->{'captcha_url'};
+    }
+    else {
+      $cgi->param('error', $error->{'message'});
+    }
+  } #if $error
 }
 
 </%init>