refactor(dynamicFields): use thrown error instead of returning it

This commit is contained in:
Ali BARIN
2023-03-01 18:00:27 +00:00
parent c6b8f12f9a
commit 63d794ed3e
2 changed files with 5 additions and 21 deletions

View File

@@ -1,22 +1,12 @@
import { IGlobalVariable, IField, IJSONObject } from '@automatisch/types'; import { IGlobalVariable } from '@automatisch/types';
export default { export default {
name: 'List fields after send as bot', name: 'List fields after send as bot',
key: 'listFieldsAfterSendAsBot', key: 'listFieldsAfterSendAsBot',
async run($: IGlobalVariable) { async run($: IGlobalVariable) {
const sendAsBot = $.step.parameters.sendAsBot as boolean; if ($.step.parameters.sendAsBot) {
return [
const remainingArguments: {
data: IJSONObject[];
error: IJSONObject | null;
} = {
data: [],
error: null,
};
if (sendAsBot) {
remainingArguments.data = [
{ {
label: 'Bot name', label: 'Bot name',
key: 'botName', key: 'botName',
@@ -38,7 +28,5 @@ export default {
}, },
]; ];
} }
return remainingArguments;
}, },
}; };

View File

@@ -40,13 +40,9 @@ const getDynamicFields = async (
$.step.parameters[parameterKey] = parameterValue; $.step.parameters[parameterKey] = parameterValue;
} }
const remainingArguments = await command.run($); const additionalFields = await command.run($) || [];
if (remainingArguments.error) { return additionalFields;
throw new Error(JSON.stringify(remainingArguments.error));
}
return remainingArguments.data;
}; };
export default getDynamicFields; export default getDynamicFields;