mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-02 07:01:30 -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 { IExecuteFunctions } from 'n8n-core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
IBinaryKeyData,
|
||||||
IDataObject,
|
IDataObject,
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
INodeType,
|
INodeType,
|
||||||
|
@ -21,6 +22,13 @@ import {
|
||||||
replaceNullValues,
|
replaceNullValues,
|
||||||
sanitizeUiMessage,
|
sanitizeUiMessage,
|
||||||
} from '../GenericFunctions';
|
} from '../GenericFunctions';
|
||||||
|
|
||||||
|
function toText<T>(data: T) {
|
||||||
|
if (typeof data === 'object' && data !== null) {
|
||||||
|
return JSON.stringify(data);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
export class HttpRequestV3 implements INodeType {
|
export class HttpRequestV3 implements INodeType {
|
||||||
description: INodeTypeDescription;
|
description: INodeTypeDescription;
|
||||||
|
|
||||||
|
@ -1289,12 +1297,10 @@ export class HttpRequestV3 implements INodeType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
const promisesResponses = await Promise.allSettled(requestPromises);
|
const promisesResponses = await Promise.allSettled(requestPromises);
|
||||||
|
|
||||||
let response: any;
|
let response: any;
|
||||||
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
||||||
// @ts-ignore
|
|
||||||
response = promisesResponses.shift();
|
response = promisesResponses.shift();
|
||||||
|
|
||||||
if (response!.status !== 'fulfilled') {
|
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
|
// Create a shallow copy of the binary data so that the old
|
||||||
// data references which do not get changed still stay behind
|
// data references which do not get changed still stay behind
|
||||||
// but the incoming data does not get changed.
|
// but the incoming data does not get changed.
|
||||||
// @ts-ignore
|
Object.assign(newItem.binary as IBinaryKeyData, items[itemIndex].binary);
|
||||||
Object.assign(newItem.binary, items[itemIndex].binary);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileName = url.split('/').pop();
|
const fileName = url.split('/').pop();
|
||||||
|
@ -1415,7 +1420,7 @@ export class HttpRequestV3 implements INodeType {
|
||||||
const returnItem: IDataObject = {};
|
const returnItem: IDataObject = {};
|
||||||
for (const property of fullReponseProperties) {
|
for (const property of fullReponseProperties) {
|
||||||
if (property === 'body') {
|
if (property === 'body') {
|
||||||
returnItem[outputPropertyName] = response![property];
|
returnItem[outputPropertyName] = toText(response![property]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1430,7 +1435,7 @@ export class HttpRequestV3 implements INodeType {
|
||||||
} else {
|
} else {
|
||||||
returnItems.push({
|
returnItems.push({
|
||||||
json: {
|
json: {
|
||||||
[outputPropertyName]: response,
|
[outputPropertyName]: toText(response),
|
||||||
},
|
},
|
||||||
pairedItem: {
|
pairedItem: {
|
||||||
item: itemIndex,
|
item: itemIndex,
|
||||||
|
|
Loading…
Reference in a new issue