Skip to content

Commit

Permalink
fix: add try catch to all query calls
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikmv committed Oct 25, 2024
1 parent 5781035 commit 56748b7
Showing 1 changed file with 50 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,57 +63,77 @@ const buildTEAUrlByElementType: {|
}: SubValueTEAProps) => {
const { teiId, value } = trackedEntity;
if (!value) return null;
const { id, displayName: name } = await querySingleResource({ resource: `fileResources/${value}` });
try {
const { id, displayName: name } = await querySingleResource({ resource: `fileResources/${value}` });

if (!latestValue) {
return name;
}
if (!latestValue) {
return name;
}

return {
id,
name,
url: `${absoluteApiPath}/tracker/trackedEntities/${teiId}/attributes/${attributeId}/image?program=${programId}`,
previewUrl: `${absoluteApiPath}/tracker/trackedEntities/${teiId}/attributes/${attributeId}/image?program=${programId}&dimension=small`,
};
return {
id,
name,
url: `${absoluteApiPath}/tracker/trackedEntities/${teiId}/attributes/${attributeId}/image?program=${programId}`,
previewUrl: `${absoluteApiPath}/tracker/trackedEntities/${teiId}/attributes/${attributeId}/image?program=${programId}&dimension=small`,
};
} catch (error) {
log.error(
errorCreator('Error fetching image resource')({ error }),
);
return null;
}
},
};


const buildDataElementUrlByElementType: {|
[string]: Function,
|} = {
[dataElementTypes.FILE_RESOURCE]: async ({ dataElement, querySingleResource, eventId, absoluteApiPath, latestValue }: SubValuesDataElementProps) => {
const { id: dataElementId, value } = dataElement;
if (!value) return null;

const { id, displayName: name } = await querySingleResource({ resource: `fileResources/${value}` });
try {
const { id, displayName: name } = await querySingleResource({ resource: `fileResources/${value}` });

if (!latestValue) {
return name;
}
if (!latestValue) {
return name;
}

return {
id,
name,
url: `${absoluteApiPath}/tracker/events/${eventId}/dataValues/${dataElementId}/file`,
};
return {
id,
name,
url: `${absoluteApiPath}/tracker/events/${eventId}/dataValues/${dataElementId}/file`,
};
} catch (error) {
log.error(
errorCreator('Error fetching file resource')({ error }),
);
return null;
}
},
[dataElementTypes.IMAGE]: async ({ dataElement, querySingleResource, eventId, absoluteApiPath, latestValue }: SubValuesDataElementProps) => {
const { id: dataElementId, value } = dataElement;
if (!value) return null;

const { id, displayName: name } = await querySingleResource({ resource: `fileResources/${value}` });
try {
const { id, displayName: name } = await querySingleResource({ resource: `fileResources/${value}` });

if (!latestValue) {
return name;
}
if (!latestValue) {
return name;
}

return {
id,
name,
url: `${absoluteApiPath}/tracker/events/${eventId}/dataValues/${dataElementId}/image`,
previewUrl: `${absoluteApiPath}/tracker/events/${eventId}/dataValues/${dataElementId}/image?dimension=small`,
};
return {
id,
name,
url: `${absoluteApiPath}/tracker/events/${eventId}/dataValues/${dataElementId}/image`,
previewUrl: `${absoluteApiPath}/tracker/events/${eventId}/dataValues/${dataElementId}/image?dimension=small`,
};
} catch (error) {
log.error(
errorCreator('Error fetching image resource')({ error }),
);
return null;
}
},
};

Expand Down

0 comments on commit 56748b7

Please sign in to comment.