mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 06:34:05 -08:00
fix(HTTP Request Node): Response format to text is ignored for JSON responses
This commit is contained in:
parent
026f3a532d
commit
8dbe6159d0
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue