Skip to content

Commit

Permalink
fix: improve error handling for parameters with dynamic values
Browse files Browse the repository at this point in the history
  • Loading branch information
csm-thu committed May 6, 2024
1 parent 54e3607 commit 1d776f6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/hooks/DynamicValuesHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ export const useDynamicValues = (parameter, targetDatasetId) => {
let data;
try {
data = await Api.Datasets.twingraphQuery(organizationId, targetDatasetId, query);
const resultKey = dynamicSourceConfig.resultKey;
const newDynamicValues = data.data.map((item) => ({ key: item[resultKey], value: item[resultKey] }));
if (newDynamicValues.length > 0 && newDynamicValues[0].key === undefined)
throw new Error(
`No property found with result key "${resultKey}" in response to dynamic values query. ` +
'Please check your dataset and your solution configuration.'
);

if (!isUnmounted.current) setDynamicValues(newDynamicValues);
} catch (error) {
console.warn(`An error occurred when loading dynamic enum values of parameter "${parameter.id}"`);
console.error(error);
Expand All @@ -66,14 +75,7 @@ export const useDynamicValues = (parameter, targetDatasetId) => {
);
dispatch(dispatchSetApplicationErrorMessage(error, errorTitle));
if (!isUnmounted.current) setDynamicValues(errorTitle);
return;
}

const newDynamicValues = data.data.map((item) => ({
key: item[dynamicSourceConfig.resultKey],
value: item[dynamicSourceConfig.resultKey],
}));
if (!isUnmounted.current) setDynamicValues(newDynamicValues);
};

setDynamicValues(dynamicSourceConfig === undefined ? undefined : null);
Expand Down

0 comments on commit 1d776f6

Please sign in to comment.