From 9a70da2bee44494fef2f9ec16fe0d596773ba4db Mon Sep 17 00:00:00 2001 From: James Rose Date: Fri, 9 Dec 2022 09:38:13 +0000 Subject: [PATCH] Log errors with logs, organisations, schemes and locations fail to import (#1074) --- app/services/imports/lettings_logs_import_service.rb | 1 + app/services/imports/organisation_import_service.rb | 8 ++++++-- app/services/imports/scheme_import_service.rb | 3 +++ app/services/imports/scheme_location_import_service.rb | 6 ++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/services/imports/lettings_logs_import_service.rb b/app/services/imports/lettings_logs_import_service.rb index ab15e7f3d..0662f1582 100644 --- a/app/services/imports/lettings_logs_import_service.rb +++ b/app/services/imports/lettings_logs_import_service.rb @@ -288,6 +288,7 @@ module Imports attributes.delete("referral") save_lettings_log(attributes, previous_status) else + @logger.error("Log #{lettings_log.old_id}: Failed to import") raise exception end end diff --git a/app/services/imports/organisation_import_service.rb b/app/services/imports/organisation_import_service.rb index 2eed9b30b..1ec1575bc 100644 --- a/app/services/imports/organisation_import_service.rb +++ b/app/services/imports/organisation_import_service.rb @@ -12,6 +12,8 @@ module Imports }.freeze def create_organisation(xml_document) + old_visible_id = organisation_field_value(xml_document, "visible-id") + Organisation.create!( name: organisation_field_value(xml_document, "name"), provider_type: PROVIDER_TYPE[organisation_field_value(xml_document, "institution-type")], @@ -32,12 +34,14 @@ module Imports supported_housing_units: organisation_field_value(xml_document, "supported-housing-units"), unspecified_units: organisation_field_value(xml_document, "unspecified-units"), old_org_id: organisation_field_value(xml_document, "id"), - old_visible_id: organisation_field_value(xml_document, "visible-id"), + old_visible_id:, ) rescue ActiveRecord::RecordNotUnique name = organisation_field_value(xml_document, "name") - old_visible_id = organisation_field_value(xml_document, "visible-id") @logger.warn("Organisation #{name} is already present with old visible ID #{old_visible_id}, skipping.") + rescue ActiveRecord::RecordInvalid + @logger.error("Organisation #{old_visible_id}: Failed to import") + raise end def organisation_field_value(xml_document, field) diff --git a/app/services/imports/scheme_import_service.rb b/app/services/imports/scheme_import_service.rb index 8be6b4603..e7440d393 100644 --- a/app/services/imports/scheme_import_service.rb +++ b/app/services/imports/scheme_import_service.rb @@ -18,6 +18,9 @@ module Imports else @logger.warn("Scheme with legacy ID #{attributes['old_id']} is not approved (#{attributes['status']}), skipping") end + rescue ActiveRecord::RecordInvalid + @logger.error("Scheme #{attributes['old_visible_id']}: Failed to import") + raise end private diff --git a/app/services/imports/scheme_location_import_service.rb b/app/services/imports/scheme_location_import_service.rb index 837be0b49..abd4a2f35 100644 --- a/app/services/imports/scheme_location_import_service.rb +++ b/app/services/imports/scheme_location_import_service.rb @@ -46,6 +46,9 @@ module Imports ) confirm_scheme(scheme) scheme.save! && scheme + rescue ActiveRecord::RecordInvalid + @logger.error("Scheme #{source_scheme.old_visible_id}: Failed to import") + raise end def update_scheme(scheme, attributes) @@ -110,6 +113,9 @@ module Imports ) rescue ActiveRecord::RecordNotUnique @logger.warn("Location is already present with legacy ID #{attributes['location_old_id']}, skipping") + rescue ActiveRecord::RecordInvalid + @logger.error("Location #{attributes['location_old_id']}: Failed to import") + raise end def find_scheme_to_merge(attributes)