From f5d25a8d2d892e062370d4ab9bc47c1cd4c36b53 Mon Sep 17 00:00:00 2001 From: Maks Turtiainen Date: Tue, 29 Aug 2023 00:21:52 +0300 Subject: [PATCH] Handle case when there's no company address --- .../shared/shared/service_bus/service_bus_client.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/backend/shared/shared/service_bus/service_bus_client.py b/backend/shared/shared/service_bus/service_bus_client.py index 6487b7e555..bfd5dc3e57 100644 --- a/backend/shared/shared/service_bus/service_bus_client.py +++ b/backend/shared/shared/service_bus/service_bus_client.py @@ -70,7 +70,12 @@ def _get_organisation_data_from_service_bus_data( that hasn't been covered in the code """ - address = cls._get_address(service_bus_data["PostalAddress"]["DomesticAddress"]) + try: + address = cls._get_address( + service_bus_data["PostalAddress"]["DomesticAddress"] + ) + except (KeyError, TypeError): + address = {"StreetAddress": "", "PostalCode": "", "City": ""} company_data = { "name": service_bus_data["TradeName"]["Name"], "business_id": service_bus_data["BusinessId"], @@ -152,10 +157,10 @@ def _get_company_form_code(legal_form_json: dict) -> int: raise ValueError("Cannot determine company form - invalid PrimaryCode") try: return int(legal_form_json["Type"]["SecondaryCode"]) - except (TypeError, ValueError) as e: + except (TypeError, ValueError) as exc: raise ValueError( "Cannot determine company form - invalid SecondaryCode" - ) from e + ) from exc @staticmethod def _get_finnish_description(descriptions: dict) -> Optional[dict]: