Skip to content

Commit

Permalink
fix(HTTP Request Node): Fix issue with requests that return null (#3498)
Browse files Browse the repository at this point in the history
* ⚡ fix

* ⚡  Remove null values at node level

* 🔥 Remove unused imports

* ⚡ Small change

Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
  • Loading branch information
michael-radency and RicardoE105 committed Jun 13, 2022
1 parent 57d4668 commit 7346da0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 8 additions & 0 deletions packages/nodes-base/nodes/HttpRequest/GenericFunctions.ts
@@ -0,0 +1,8 @@
import { INodeExecutionData } from "n8n-workflow";

export const replaceNullValues = (item: INodeExecutionData) => {
if (item.json === null) {
item.json = {};
}
return item;
};
11 changes: 5 additions & 6 deletions packages/nodes-base/nodes/HttpRequest/HttpRequest.node.ts
@@ -1,21 +1,18 @@
import path from 'path';
import {
IExecuteFunctions,
} from 'n8n-core';
import {
IAuthenticate,
IBinaryData,
IDataObject,
ILoadOptionsFunctions,
INodeExecutionData,
INodePropertyOptions,
INodeType,
INodeTypeDescription,
NodeApiError,
NodeOperationError,
} from 'n8n-workflow';

import { OptionsWithUri } from 'request';
import { replaceNullValues } from './GenericFunctions';

interface OptionData {
name: string;
Expand Down Expand Up @@ -919,8 +916,7 @@ export class HttpRequest implements INodeType {
displayName: 'Query Paramters',
},
};

const returnItems: INodeExecutionData[] = [];
let returnItems: INodeExecutionData[] = [];
const requestPromises = [];
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
const requestMethod = this.getNodeParameter('requestMethod', itemIndex) as string;
Expand Down Expand Up @@ -1263,6 +1259,7 @@ export class HttpRequest implements INodeType {
// Create a shallow copy of the binary data so that the old
// data references which do not get changed still stay behind
// but the incoming data does not get changed.
// @ts-ignore
Object.assign(newItem.binary, items[itemIndex].binary);
}

Expand Down Expand Up @@ -1367,6 +1364,8 @@ export class HttpRequest implements INodeType {
}
}

returnItems = returnItems.map(replaceNullValues);

return this.prepareOutputData(returnItems);
}
}

0 comments on commit 7346da0

Please sign in to comment.