Skip to content

Commit

Permalink
Handle case when there's no company address
Browse files Browse the repository at this point in the history
  • Loading branch information
mjturt committed Aug 28, 2023
1 parent c634724 commit 8132fa6
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions backend/shared/shared/service_bus/service_bus_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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]:
Expand Down

0 comments on commit 8132fa6

Please sign in to comment.