mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
fix(HTTP Request Node): Continue using error (#11733)
This commit is contained in:
@@ -106,6 +106,7 @@ export class HttpRequestV3 implements INodeType {
|
||||
};
|
||||
|
||||
let returnItems: INodeExecutionData[] = [];
|
||||
const errorItems: { [key: string]: string } = {};
|
||||
const requestPromises = [];
|
||||
|
||||
let fullResponse = false;
|
||||
@@ -140,6 +141,7 @@ export class HttpRequestV3 implements INodeType {
|
||||
}> = [];
|
||||
|
||||
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
||||
try {
|
||||
if (authentication === 'genericCredentialType') {
|
||||
genericCredentialType = this.getNodeParameter('genericAuthType', 0) as string;
|
||||
|
||||
@@ -404,9 +406,13 @@ export class HttpRequestV3 implements INodeType {
|
||||
try {
|
||||
JSON.parse(jsonQueryParameter);
|
||||
} catch {
|
||||
throw new NodeOperationError(this.getNode(), 'JSON parameter needs to be valid JSON', {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'JSON parameter needs to be valid JSON',
|
||||
{
|
||||
itemIndex,
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
requestOptions.qs = jsonParse(jsonQueryParameter);
|
||||
@@ -426,9 +432,13 @@ export class HttpRequestV3 implements INodeType {
|
||||
try {
|
||||
JSON.parse(jsonHeadersParameter);
|
||||
} catch {
|
||||
throw new NodeOperationError(this.getNode(), 'JSON parameter needs to be valid JSON', {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'JSON parameter needs to be valid JSON',
|
||||
{
|
||||
itemIndex,
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
additionalHeaders = jsonParse(jsonHeadersParameter);
|
||||
@@ -566,7 +576,11 @@ export class HttpRequestV3 implements INodeType {
|
||||
// Iterate over all parameters and add them to the request
|
||||
paginationData.request = {};
|
||||
const { parameters } = pagination.parameters;
|
||||
if (parameters.length === 1 && parameters[0].name === '' && parameters[0].value === '') {
|
||||
if (
|
||||
parameters.length === 1 &&
|
||||
parameters[0].name === '' &&
|
||||
parameters[0].value === ''
|
||||
) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
"At least one entry with 'Name' and 'Value' filled must be included in 'Parameters' to use 'Update a Parameter in Each Request' mode ",
|
||||
@@ -628,13 +642,22 @@ export class HttpRequestV3 implements INodeType {
|
||||
requestPromises.push(requestPromise);
|
||||
} else if (authentication === 'genericCredentialType' || authentication === 'none') {
|
||||
if (oAuth1Api) {
|
||||
const requestOAuth1 = this.helpers.requestOAuth1.call(this, 'oAuth1Api', requestOptions);
|
||||
const requestOAuth1 = this.helpers.requestOAuth1.call(
|
||||
this,
|
||||
'oAuth1Api',
|
||||
requestOptions,
|
||||
);
|
||||
requestOAuth1.catch(() => {});
|
||||
requestPromises.push(requestOAuth1);
|
||||
} else if (oAuth2Api) {
|
||||
const requestOAuth2 = this.helpers.requestOAuth2.call(this, 'oAuth2Api', requestOptions, {
|
||||
const requestOAuth2 = this.helpers.requestOAuth2.call(
|
||||
this,
|
||||
'oAuth2Api',
|
||||
requestOptions,
|
||||
{
|
||||
tokenType: 'Bearer',
|
||||
});
|
||||
},
|
||||
);
|
||||
requestOAuth2.catch(() => {});
|
||||
requestPromises.push(requestOAuth2);
|
||||
} else {
|
||||
@@ -658,13 +681,25 @@ export class HttpRequestV3 implements INodeType {
|
||||
requestWithAuthentication.catch(() => {});
|
||||
requestPromises.push(requestWithAuthentication);
|
||||
}
|
||||
} catch (error) {
|
||||
if (!this.continueOnFail()) throw error;
|
||||
|
||||
requestPromises.push(Promise.reject(error).catch(() => {}));
|
||||
|
||||
errorItems[itemIndex] = error.message;
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
const sanitizedRequests: IDataObject[] = [];
|
||||
const promisesResponses = await Promise.allSettled(
|
||||
requestPromises.map(
|
||||
async (requestPromise, itemIndex) =>
|
||||
await requestPromise.finally(async () => {
|
||||
await requestPromise
|
||||
.then((response) => response)
|
||||
.finally(async () => {
|
||||
if (errorItems[itemIndex]) return;
|
||||
try {
|
||||
// Secrets need to be read after the request because secrets could have changed
|
||||
// For example: OAuth token refresh, preAuthentication
|
||||
@@ -686,6 +721,16 @@ export class HttpRequestV3 implements INodeType {
|
||||
let responseData: any;
|
||||
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
||||
responseData = promisesResponses.shift();
|
||||
|
||||
if (errorItems[itemIndex]) {
|
||||
returnItems.push({
|
||||
json: { error: errorItems[itemIndex] },
|
||||
pairedItem: { item: itemIndex },
|
||||
});
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (responseData!.status !== 'fulfilled') {
|
||||
if (responseData.reason.statusCode === 429) {
|
||||
responseData.reason.message =
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
{
|
||||
"name": "HTTP Request Node: Continue using error output not working",
|
||||
"nodes": [
|
||||
{
|
||||
"parameters": {},
|
||||
"id": "6e15f2de-79fe-41f3-b76e-53ebfa2e4437",
|
||||
"name": "When clicking ‘Test workflow’",
|
||||
"type": "n8n-nodes-base.manualTrigger",
|
||||
"typeVersion": 1,
|
||||
"position": [-60, 580]
|
||||
},
|
||||
{
|
||||
"parameters": {},
|
||||
"id": "af1bb989-3c6d-4323-8e88-649e45d64c00",
|
||||
"name": "Success path",
|
||||
"type": "n8n-nodes-base.noOp",
|
||||
"typeVersion": 1,
|
||||
"position": [460, 460]
|
||||
},
|
||||
{
|
||||
"parameters": {},
|
||||
"id": "43c4ee19-6a9d-4b1d-aefa-2c24abe45189",
|
||||
"name": "Error path",
|
||||
"type": "n8n-nodes-base.noOp",
|
||||
"typeVersion": 1,
|
||||
"position": [460, 700]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"method": "POST",
|
||||
"url": "https://webhook.site/e18fe8f9-ec77-4574-a40d-8ae054191e1e",
|
||||
"sendBody": true,
|
||||
"specifyBody": "json",
|
||||
"jsonBody": "{\n \"q\": \"abc\",\n}",
|
||||
"options": {}
|
||||
},
|
||||
"id": "31641920-7f43-473f-ad96-b121122802bb",
|
||||
"name": "HTTP Request",
|
||||
"type": "n8n-nodes-base.httpRequest",
|
||||
"typeVersion": 4.2,
|
||||
"position": [180, 580],
|
||||
"alwaysOutputData": false,
|
||||
"onError": "continueErrorOutput"
|
||||
}
|
||||
],
|
||||
"pinData": {
|
||||
"Error path": [
|
||||
{
|
||||
"json": {
|
||||
"error": "JSON parameter needs to be valid JSON"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"connections": {
|
||||
"When clicking ‘Test workflow’": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "HTTP Request",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"HTTP Request": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Success path",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"node": "Error path",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
"active": false,
|
||||
"settings": {
|
||||
"executionOrder": "v1"
|
||||
},
|
||||
"versionId": "f445a6e9-818f-4b70-8b4f-e2a68fc5d6e4",
|
||||
"meta": {
|
||||
"templateCredsSetupCompleted": true,
|
||||
"instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd"
|
||||
},
|
||||
"id": "f3rDILaMkFqisP3P",
|
||||
"tags": []
|
||||
}
|
||||
Reference in New Issue
Block a user