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 {
name: 'List fields after send as bot',
key: 'listFieldsAfterSendAsBot',
async run($: IGlobalVariable) {
const sendAsBot = $.step.parameters.sendAsBot as boolean;
const remainingArguments: {
data: IJSONObject[];
error: IJSONObject | null;
} = {
data: [],
error: null,
};
if (sendAsBot) {
remainingArguments.data = [
if ($.step.parameters.sendAsBot) {
return [
{
label: 'Bot name',
key: 'botName',
@@ -38,7 +28,5 @@ export default {
},
];
}
return remainingArguments;
},
};

View File

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