Skip to content

Commit

Permalink
fix query logic
Browse files Browse the repository at this point in the history
  • Loading branch information
bjosttveit committed Oct 4, 2023
1 parent 7c75a70 commit 0b8118f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/hooks/queries/useCustomValidationConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ export const useCustomValidationConfig = (): UseQueryResult<IExpressionValidatio
return useQuery(['fetchCustomValidationConfig', dataTypeId], () => fetchCustomValidationConfig(dataTypeId), {
enabled: Boolean(dataTypeId?.length),
onSuccess: (customValidationConfig) => {
if (!customValidationConfig) {
return;
if (customValidationConfig) {
const validationDefinition = resolveExpressionValidationConfig(customValidationConfig);
dispatch(CustomValidationActions.fetchCustomValidationsFulfilled(validationDefinition));
} else {
dispatch(CustomValidationActions.fetchCustomValidationsRejected(null));
}
const validationDefinition = resolveExpressionValidationConfig(customValidationConfig);
dispatch(CustomValidationActions.fetchCustomValidationsFulfilled(validationDefinition));
},
onError: (error: AxiosError) => {
if (error.response?.status !== 404) {
if (error.response?.status === 404) {
dispatch(CustomValidationActions.fetchCustomValidationsRejected(null));
window.logWarn('App does not support custom validation using expressions');
} else {
dispatch(CustomValidationActions.fetchCustomValidationsRejected(error));
window.logError('Fetching validation configuration failed:\n', error);
}
Expand Down

0 comments on commit 0b8118f

Please sign in to comment.