From 152c54a5c8277fb09429d6ded83535edd0a914f2 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Tue, 22 Dec 2015 17:03:07 -0800 Subject: [PATCH] improve handling of internal errors from US Census geocoding, #39549 --- FS/FS/Misc/Geo.pm | 8 ++++++-- FS/FS/geocode_Mixin.pm | 2 +- FS/FS/log.pm | 2 +- FS/FS/log_context.pm | 1 + httemplate/elements/standardize_locations.js | 7 ++++++- httemplate/search/log.html | 2 +- 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/FS/FS/Misc/Geo.pm b/FS/FS/Misc/Geo.pm index 168e4e959..c02d5dd0e 100644 --- a/FS/FS/Misc/Geo.pm +++ b/FS/FS/Misc/Geo.pm @@ -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 } } diff --git a/FS/FS/geocode_Mixin.pm b/FS/FS/geocode_Mixin.pm index 0625b5ac3..bc8c1180d 100644 --- a/FS/FS/geocode_Mixin.pm +++ b/FS/FS/geocode_Mixin.pm @@ -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 { diff --git a/FS/FS/log.pm b/FS/FS/log.pm index a4ad214d0..753a31f95 100644 --- a/FS/FS/log.pm +++ b/FS/FS/log.pm @@ -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; diff --git a/FS/FS/log_context.pm b/FS/FS/log_context.pm index b2126b8cb..718b4d54a 100644 --- a/FS/FS/log_context.pm +++ b/FS/FS/log_context.pm @@ -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 diff --git a/httemplate/elements/standardize_locations.js b/httemplate/elements/standardize_locations.js index c2857377a..fed57334a 100644 --- a/httemplate/elements/standardize_locations.js +++ b/httemplate/elements/standardize_locations.js @@ -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 { diff --git a/httemplate/search/log.html b/httemplate/search/log.html index d1bfb6cc9..7714f4614 100644 --- a/httemplate/search/log.html +++ b/httemplate/search/log.html @@ -137,7 +137,7 @@ my $tt_sub = sub { return '' if @context == 1 and length($log->message) <= 60; my $html = '
'.(shift @context).'
'; my $pre = '↳'; - foreach (@context, $log->message) { + foreach (map encode_entities($_), @context, $log->message) { $html .= "
$pre$_
"; $pre = '   '.$pre; } -- 2.11.0