improve handling of internal errors from US Census geocoding, #39549
authorMark Wells <mark@freeside.biz>
Wed, 23 Dec 2015 01:03:07 +0000 (17:03 -0800)
committerMark Wells <mark@freeside.biz>
Wed, 23 Dec 2015 01:22:26 +0000 (17:22 -0800)
FS/FS/Misc/Geo.pm
FS/FS/geocode_Mixin.pm
FS/FS/log.pm
FS/FS/log_context.pm
httemplate/elements/standardize_locations.js
httemplate/search/log.html

index 168e4e9..c02d5dd 100644 (file)
@@ -11,6 +11,7 @@ use JSON;
 use URI::Escape 3.31;
 use Data::Dumper;
 use FS::Conf;
+use FS::Log;
 use Locale::Country;
 
 FS::UID->install_callback( sub {
@@ -300,6 +301,8 @@ sub standardize_usps {
 sub standardize_uscensus {
   my $self = shift;
   my $location = shift;
+  my $log = FS::Log->new('FS::Misc::Geo::standardize_uscensus');
+  $log->debug(join("\n", @{$location}{'address1', 'city', 'state', 'zip'}));
 
   eval "use Geo::USCensus::Geocoding";
   die $@ if $@;
@@ -322,6 +325,7 @@ sub standardize_uscensus {
   my $result = Geo::USCensus::Geocoding->query($request);
   if ( $result->is_match ) {
     # unfortunately we get the address back as a single line
+    $log->debug($result->address);
     if ($result->address =~ /^(.*), (.*), ([A-Z]{2}), (\d{5}.*)$/) {
       return +{
         address1    => $1,
@@ -341,8 +345,8 @@ sub standardize_uscensus {
   } elsif ( $result->match_level ) {
     die "Geocoding did not find a matching address.\n";
   } else {
-    warn Dumper($result) if $DEBUG;
-    die $result->error_message;
+    $log->error($result->error_message);
+    return; # for internal errors, don't return anything
   }
 }
 
index 0625b5a..bc8c118 100644 (file)
@@ -140,7 +140,7 @@ Returns the full country name.
 
 sub country_full {
   my $self = shift;
-  $self->code2country($self->country);
+  $self->code2country($self->get('country'));
 }
 
 sub code2country {
index a4ad214..753a31f 100644 (file)
@@ -114,7 +114,7 @@ sub check {
     || $self->ut_textn('tablename')
     || $self->ut_numbern('tablenum')
     || $self->ut_number('level')
-    || $self->ut_text('message')
+    || $self->ut_anything('message')
   ;
   return $error if $error;
 
index b2126b8..718b4d5 100644 (file)
@@ -9,6 +9,7 @@ my @contexts = ( qw(
   bill_and_collect
   FS::cust_main::Billing::bill_and_collect
   FS::cust_main::Billing::bill
+  FS::Misc::Geo::standardize_uscensus
   Cron::bill
   Cron::upload
   spool_upload
index c285737..fed5733 100644 (file)
@@ -114,7 +114,12 @@ function confirm_standardize(arg) {
 
     // then all entered address fields are correct
     // but we still need to set the lat/long fields and addr_clean
-    status_message('Verified');
+
+    if ( returned['addr_clean'] ) {
+      status_message('Verified');
+    } else {
+      status_message('Unverified');
+    }
     replace_address();
 
   } else {
index d1bfb6c..7714f46 100644 (file)
@@ -137,7 +137,7 @@ my $tt_sub = sub {
   return '' if @context == 1 and length($log->message) <= 60;
   my $html = '<DIV CLASS="tooltip">'.(shift @context).'</DIV>';
   my $pre = '&#8627;';
-  foreach (@context, $log->message) {
+  foreach (map encode_entities($_), @context, $log->message) {
     $html .= "<DIV>$pre$_</DIV>";
     $pre = '&nbsp;&nbsp;&nbsp;'.$pre;
   }