fix(HTTP Request Node): Response format to text is ignored for JSON responses

This commit is contained in:
Michael Kret 2023-01-18 15:31:39 +02:00 committed by GitHub
parent 026f3a532d
commit 8dbe6159d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,7 @@
import { IExecuteFunctions } from 'n8n-core';
import {
IBinaryKeyData,
IDataObject,
INodeExecutionData,
INodeType,
@ -21,6 +22,13 @@ import {
replaceNullValues,
sanitizeUiMessage,
} from '../GenericFunctions';
function toText<T>(data: T) {
if (typeof data === 'object' && data !== null) {
return JSON.stringify(data);
}
return data;
}
export class HttpRequestV3 implements INodeType {
description: INodeTypeDescription;
@ -1289,12 +1297,10 @@ export class HttpRequestV3 implements INodeType {
}
}
// @ts-ignore
const promisesResponses = await Promise.allSettled(requestPromises);
let response: any;
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
// @ts-ignore
response = promisesResponses.shift();
if (response!.status !== 'fulfilled') {
@ -1374,8 +1380,7 @@ export class HttpRequestV3 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);
Object.assign(newItem.binary as IBinaryKeyData, items[itemIndex].binary);
}
const fileName = url.split('/').pop();
@ -1415,7 +1420,7 @@ export class HttpRequestV3 implements INodeType {
const returnItem: IDataObject = {};
for (const property of fullReponseProperties) {
if (property === 'body') {
returnItem[outputPropertyName] = response![property];
returnItem[outputPropertyName] = toText(response![property]);
continue;
}
@ -1430,7 +1435,7 @@ export class HttpRequestV3 implements INodeType {
} else {
returnItems.push({
json: {
[outputPropertyName]: response,
[outputPropertyName]: toText(response),
},
pairedItem: {
item: itemIndex,