Skip to content

Commit

Permalink
fix: allow companies without address
Browse files Browse the repository at this point in the history
Fix YTJ (Service Bus) integration to allow companies to be saved without address.
  • Loading branch information
mjturt committed Aug 30, 2023
1 parent a6d126f commit 90da326
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 90da326

Please sign in to comment.