PAS falls back to coordination client when UPRN lookup returns 401 🟩

This commit is contained in:
Daniel Roth 2026-05-18 09:06:46 +00:00
parent a999724578
commit e044638192

View file

@ -44,12 +44,26 @@ class PashubService:
self._coordination_client_factory = coordination_client_factory
self._coordination_client: Optional[PashubClient] = None
def _get_coordination_client(self) -> PashubClient:
if self._coordination_client_factory is None:
raise UnauthorizedError("No coordination client factory configured")
if self._coordination_client is None:
self._coordination_client = self._coordination_client_factory()
return self._coordination_client
def run(self, request: PashubToAraTriggerRequest) -> List[str]:
job_id = request.pashub_job_id
active_client = self._pashub_client
if request.uprn:
uprn: Optional[str] = request.uprn
else:
try:
uprn = active_client.get_uprn_by_job_id(job_id)
except UnauthorizedError:
active_client = self._get_coordination_client()
uprn = active_client.get_uprn_by_job_id(job_id)
uprn: Optional[str] = request.uprn or self._pashub_client.get_uprn_by_job_id(
job_id
)
hubspot_deal_id: Optional[str] = request.hubspot_deal_id
if uprn:
@ -57,7 +71,7 @@ class PashubService:
else:
logger.info(f"No UPRN found for job {job_id}")
job_files: List[str] = self._pashub_client.get_core_evidence_files_by_job_id(
job_files: List[str] = active_client.get_core_evidence_files_by_job_id(
job_id
)