diff options
author | Matthew Somerville <matthew@mysociety.org> | 2016-06-15 13:22:11 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2016-06-15 13:47:53 +0100 |
commit | 576e65e5b9116899655bf1db4bce2bd6b412e91f (patch) | |
tree | 8e22c707b2232019946fb555cdce296537060482 /perllib/Open311 | |
parent | 8d428f9c8fd9e25821560a20d00d444d9fb67e08 (diff) |
Fail nicely if Open311 response lacks service code
Diffstat (limited to 'perllib/Open311')
-rw-r--r-- | perllib/Open311/PopulateServiceList.pm | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm index dd3bd65d6..7c709babf 100644 --- a/perllib/Open311/PopulateServiceList.pm +++ b/perllib/Open311/PopulateServiceList.pm @@ -81,17 +81,21 @@ sub process_services { sub process_service { my $self = shift; - my $category = $self->_current_body->areas->{2218} ? - $self->_current_service->{description} : - $self->_current_service->{service_name}; + my $service_name = $self->_normalize_service_name; + + unless ($self->_current_service->{service_code}) { + warn "Service $service_name has no service code for body @{[$self->_current_body->id]}\n" + if $self->verbose >= 1; + return; + } - print $self->_current_service->{service_code} . ': ' . $category . "\n" if $self->verbose >= 2; + print $self->_current_service->{service_code} . ': ' . $service_name . "\n" if $self->verbose >= 2; my $contacts = $self->schema->resultset('Contact')->search( { body_id => $self->_current_body->id, -OR => [ email => $self->_current_service->{service_code}, - category => $category, + category => $service_name, ] } ); @@ -100,7 +104,7 @@ sub process_service { printf( "Multiple contacts for service code %s, category %s - Skipping\n", $self->_current_service->{service_code}, - $category, + $service_name, ); # best to not mark them as deleted as we don't know what we're doing |