From f0c14fb4ecca121db4ce151caf9d7c4005bfd769 Mon Sep 17 00:00:00 2001 From: martin-nhs Date: Fri, 10 May 2024 10:05:19 +0100 Subject: [PATCH] [PRMT-4832] Added additional logging to sds-fhir-client.js --- src/services/fhir/sds-fhir-client.js | 31 ++++++++++++++++++---------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/services/fhir/sds-fhir-client.js b/src/services/fhir/sds-fhir-client.js index dd5e5291..42ef4f4a 100644 --- a/src/services/fhir/sds-fhir-client.js +++ b/src/services/fhir/sds-fhir-client.js @@ -6,17 +6,26 @@ export const getPracticeAsid = async (odsCode, serviceId) => { const { sdsFhirUrl, sdsFhirApiKey } = initializeConfig(); logInfo(`Getting ASID via FHIR for ODS code ${odsCode}`); try { - const response = await axios.get(`${sdsFhirUrl}/Device`, { - params: { - organization: `https://fhir.nhs.uk/Id/ods-organization-code|${odsCode}`, - identifier: `https://fhir.nhs.uk/Id/nhsServiceInteractionId|${serviceId}` - }, - headers: { - apiKey: sdsFhirApiKey - } - }); - - const entries = response.data.entry; + const entries = axios + .get(`${sdsFhirUrl}/Device`, { + params: { + organization: `https://fhir.nhs.uk/Id/ods-organization-code|${odsCode}`, + identifier: `https://fhir.nhs.uk/Id/nhsServiceInteractionId|${serviceId}` + }, + headers: { + apiKey: sdsFhirApiKey + } + }) + .then(response => response.data.entry) + .catch(error => { + logError( + `Error: Request failed with non-2xx status code\n + Response body: ${error.response.data}\n + HTTP Status code: ${error.response.status}` + ); + + throw error; + }); if (entries.length === 0) { throw new Error(`No ASID entries found for ODS code ${odsCode}`);