1
1
mirror of https://github.com/n8n-io/n8n.git synced 2024-09-21 09:59:34 +03:00

Improve continueOnFail behaviour

This commit is contained in:
Jan Oberhauser 2020-03-17 13:18:04 +01:00
parent 3bf0a9ab10
commit ce0aaeba7d
4 changed files with 46 additions and 5 deletions

View File

@ -249,6 +249,19 @@ export function getNodeParameter(workflow: Workflow, runExecutionData: IRunExecu
/**
* Returns if execution should be continued even if there was an error.
*
* @export
* @param {INode} node
* @returns {boolean}
*/
export function continueOnFail(node: INode): boolean {
return get(node, 'continueOnFail', false);
}
/** /**
* Returns the webhook URL of the webhook with the given name * Returns the webhook URL of the webhook with the given name
* *
@ -474,6 +487,9 @@ export function getExecuteTriggerFunctions(workflow: Workflow, node: INode, addi
export function getExecuteFunctions(workflow: Workflow, runExecutionData: IRunExecutionData, runIndex: number, connectionInputData: INodeExecutionData[], inputData: ITaskDataConnections, node: INode, additionalData: IWorkflowExecuteAdditionalData, mode: WorkflowExecuteMode): IExecuteFunctions { export function getExecuteFunctions(workflow: Workflow, runExecutionData: IRunExecutionData, runIndex: number, connectionInputData: INodeExecutionData[], inputData: ITaskDataConnections, node: INode, additionalData: IWorkflowExecuteAdditionalData, mode: WorkflowExecuteMode): IExecuteFunctions {
return ((workflow, runExecutionData, connectionInputData, inputData, node) => { return ((workflow, runExecutionData, connectionInputData, inputData, node) => {
return { return {
continueOnFail: () => {
return continueOnFail(node);
},
async executeWorkflow(workflowInfo: IExecuteWorkflowInfo, inputData?: INodeExecutionData[]): Promise<any> { // tslint:disable-line:no-any async executeWorkflow(workflowInfo: IExecuteWorkflowInfo, inputData?: INodeExecutionData[]): Promise<any> { // tslint:disable-line:no-any
return additionalData.executeWorkflow(workflowInfo, additionalData, inputData); return additionalData.executeWorkflow(workflowInfo, additionalData, inputData);
}, },
@ -559,6 +575,9 @@ export function getExecuteFunctions(workflow: Workflow, runExecutionData: IRunEx
export function getExecuteSingleFunctions(workflow: Workflow, runExecutionData: IRunExecutionData, runIndex: number, connectionInputData: INodeExecutionData[], inputData: ITaskDataConnections, node: INode, itemIndex: number, additionalData: IWorkflowExecuteAdditionalData, mode: WorkflowExecuteMode): IExecuteSingleFunctions { export function getExecuteSingleFunctions(workflow: Workflow, runExecutionData: IRunExecutionData, runIndex: number, connectionInputData: INodeExecutionData[], inputData: ITaskDataConnections, node: INode, itemIndex: number, additionalData: IWorkflowExecuteAdditionalData, mode: WorkflowExecuteMode): IExecuteSingleFunctions {
return ((workflow, runExecutionData, connectionInputData, inputData, node, itemIndex) => { return ((workflow, runExecutionData, connectionInputData, inputData, node, itemIndex) => {
return { return {
continueOnFail: () => {
return continueOnFail(node);
},
getContext(type: string): IContextObject { getContext(type: string): IContextObject {
return NodeHelpers.getContext(runExecutionData, type, node); return NodeHelpers.getContext(runExecutionData, type, node);
}, },

View File

@ -586,9 +586,10 @@ export class HttpRequest implements INodeType {
}, },
}; };
let response: any; // tslint:disable-line:no-any
const returnItems: INodeExecutionData[] = []; const returnItems: INodeExecutionData[] = [];
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
const options = this.getNodeParameter('options', 0, {}) as IDataObject; const options = this.getNodeParameter('options', itemIndex, {}) as IDataObject;
const url = this.getNodeParameter('url', itemIndex) as string; const url = this.getNodeParameter('url', itemIndex) as string;
const fullResponse = !!options.fullResponse as boolean; const fullResponse = !!options.fullResponse as boolean;
@ -741,8 +742,17 @@ export class HttpRequest implements INodeType {
requestOptions.json = true; requestOptions.json = true;
} }
// Now that the options are all set make the actual http request try {
const response = await this.helpers.request(requestOptions); // Now that the options are all set make the actual http request
response = await this.helpers.request(requestOptions);
} catch (error) {
if (this.continueOnFail() === true) {
returnItems.push({ json: { error } });
continue;
}
throw error;
}
if (responseFormat === 'file') { if (responseFormat === 'file') {
const dataPropertyName = this.getNodeParameter('dataPropertyName', 0) as string; const dataPropertyName = this.getNodeParameter('dataPropertyName', 0) as string;

View File

@ -457,12 +457,12 @@ export class NextCloud implements INodeType {
let endpoint = ''; let endpoint = '';
let requestMethod = ''; let requestMethod = '';
let responseData: any; // tslint:disable-line:no-any
let body: string | Buffer = ''; let body: string | Buffer = '';
const headers: IDataObject = {}; const headers: IDataObject = {};
for (let i = 0; i < items.length; i++) { for (let i = 0; i < items.length; i++) {
if (resource === 'file') { if (resource === 'file') {
if (operation === 'download') { if (operation === 'download') {
// ---------------------------------- // ----------------------------------
@ -580,7 +580,16 @@ export class NextCloud implements INodeType {
options.encoding = null; options.encoding = null;
} }
const responseData = await this.helpers.request(options); try {
responseData = await this.helpers.request(options);
} catch (error) {
if (this.continueOnFail() === true) {
returnData.push({ error });
continue;
}
throw error;
}
if (resource === 'file' && operation === 'download') { if (resource === 'file' && operation === 'download') {
@ -656,6 +665,7 @@ export class NextCloud implements INodeType {
} else { } else {
returnData.push(responseData as IDataObject); returnData.push(responseData as IDataObject);
} }
} }
if (resource === 'file' && operation === 'download') { if (resource === 'file' && operation === 'download') {

View File

@ -154,6 +154,7 @@ export interface IExecuteContextData {
export interface IExecuteFunctions { export interface IExecuteFunctions {
continueOnFail(): boolean;
executeWorkflow(workflowInfo: IExecuteWorkflowInfo, inputData?: INodeExecutionData[]): Promise<any>; // tslint:disable-line:no-any executeWorkflow(workflowInfo: IExecuteWorkflowInfo, inputData?: INodeExecutionData[]): Promise<any>; // tslint:disable-line:no-any
getContext(type: string): IContextObject; getContext(type: string): IContextObject;
getCredentials(type: string): ICredentialDataDecryptedObject | undefined; getCredentials(type: string): ICredentialDataDecryptedObject | undefined;
@ -174,6 +175,7 @@ export interface IExecuteFunctions {
export interface IExecuteSingleFunctions { export interface IExecuteSingleFunctions {
continueOnFail(): boolean;
getContext(type: string): IContextObject; getContext(type: string): IContextObject;
getCredentials(type: string): ICredentialDataDecryptedObject | undefined; getCredentials(type: string): ICredentialDataDecryptedObject | undefined;
getInputData(inputIndex?: number, inputName?: string): INodeExecutionData; getInputData(inputIndex?: number, inputName?: string): INodeExecutionData;