Skip to content

Commit

Permalink
clean up error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mythilytm committed Oct 24, 2024
1 parent 1e50202 commit e8d35a7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion plugin-hrm-form/src/components/search/SearchForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const SearchForm: React.FC<Props> = ({
[channelTypes.voice]: 'PreviousContacts-PhoneNumber',
[channelTypes.sms]: 'PreviousContacts-PhoneNumber',
[channelTypes.whatsapp]: 'PreviousContacts-WhatsappNumber',
[channelTypes.messenger]: 'PreviousContacts-FacebookUser',
[channelTypes.facebook]: 'PreviousContacts-FacebookUser',
[channelTypes.telegram]: 'PreviousContacts-TelegramUser',
[channelTypes.instagram]: 'PreviousContacts-InstagramUser',
[channelTypes.line]: 'PreviousContacts-LineUser',
Expand Down
15 changes: 4 additions & 11 deletions plugin-hrm-form/src/utils/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,13 @@ export const getNumberFromTask = (task: CustomITask) => {
return getContactValueFromWebchat(task);
}

const transformedNumber = channelTransformations[channelType as ChannelTypes];

// Ensure transformedNumber is an array before calling reduce
if ((!Array.isArray(transformedNumber) || transformedNumber.length === 0) && channelType !== undefined) {
console.error(`Channel type ${channelType} is not supported or transformation array is invalid`, transformedNumber);
return null;
}

if (defaultFrom === undefined || defaultFrom === null || !defaultFrom) {
console.error(`defaultFrom is undefined for channelType ${channelType}`);
if (!channelTransformations[channelType] && channelType !== 'undefined') {
console.error(`Channel type ${channelType} is not supported`);
return null;
}

return transformedNumber.reduce((accum, f) => f(accum), defaultFrom);
// otherwise, return the "defaultFrom" with the transformations on the identifier corresponding to each channel
return channelTransformations[channelType as ChannelTypes].reduce((accum, f) => f(accum), defaultFrom);
};

/**
Expand Down

0 comments on commit e8d35a7

Please sign in to comment.