mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(HTTP Request Node): Handle response errors correctly when continueOnFail is set (#18207)
Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
@@ -748,6 +748,7 @@ export class HttpRequestV3 implements INodeType {
|
|||||||
|
|
||||||
let responseData: any;
|
let responseData: any;
|
||||||
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
||||||
|
try {
|
||||||
responseData = promisesResponses.shift();
|
responseData = promisesResponses.shift();
|
||||||
|
|
||||||
if (errorItems[itemIndex]) {
|
if (errorItems[itemIndex]) {
|
||||||
@@ -766,7 +767,9 @@ export class HttpRequestV3 implements INodeType {
|
|||||||
}
|
}
|
||||||
if (!this.continueOnFail()) {
|
if (!this.continueOnFail()) {
|
||||||
if (autoDetectResponseFormat && responseData.reason.error instanceof Buffer) {
|
if (autoDetectResponseFormat && responseData.reason.error instanceof Buffer) {
|
||||||
responseData.reason.error = Buffer.from(responseData.reason.error as Buffer).toString();
|
responseData.reason.error = Buffer.from(
|
||||||
|
responseData.reason.error as Buffer,
|
||||||
|
).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
let error;
|
let error;
|
||||||
@@ -1019,6 +1022,16 @@ export class HttpRequestV3 implements INodeType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (!this.continueOnFail()) throw error;
|
||||||
|
|
||||||
|
returnItems.push({
|
||||||
|
json: { error: error.message },
|
||||||
|
pairedItem: { item: itemIndex },
|
||||||
|
});
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
returnItems = returnItems.map(replaceNullValues);
|
returnItems = returnItems.map(replaceNullValues);
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ describe('Test HTTP Request Node', () => {
|
|||||||
completed: false,
|
completed: false,
|
||||||
userId: 15,
|
userId: 15,
|
||||||
});
|
});
|
||||||
|
nock(baseUrl).get('/html').reply(200, '<html><body><h1>Test</h1></body></html>');
|
||||||
|
|
||||||
//PUT
|
//PUT
|
||||||
nock(baseUrl).put('/todos/10', { userId: '42' }).reply(200, {
|
nock(baseUrl).put('/todos/10', { userId: '42' }).reply(200, {
|
||||||
|
|||||||
@@ -3,53 +3,95 @@
|
|||||||
"nodes": [
|
"nodes": [
|
||||||
{
|
{
|
||||||
"parameters": {},
|
"parameters": {},
|
||||||
"id": "6e15f2de-79fe-41f3-b76e-53ebfa2e4437",
|
"id": "6707decf-7ae3-46f1-8603-b0fe4844f240",
|
||||||
"name": "When clicking ‘Execute workflow’",
|
"name": "When clicking ‘Execute workflow’",
|
||||||
"type": "n8n-nodes-base.manualTrigger",
|
"type": "n8n-nodes-base.manualTrigger",
|
||||||
"typeVersion": 1,
|
"typeVersion": 1,
|
||||||
"position": [-60, 580]
|
"position": [16, 560]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"parameters": {},
|
"parameters": {},
|
||||||
"id": "af1bb989-3c6d-4323-8e88-649e45d64c00",
|
"id": "09b63a84-789d-4a31-b546-849ba47ed689",
|
||||||
"name": "Success path",
|
"name": "Success path",
|
||||||
"type": "n8n-nodes-base.noOp",
|
"type": "n8n-nodes-base.noOp",
|
||||||
"typeVersion": 1,
|
"typeVersion": 1,
|
||||||
"position": [460, 460]
|
"position": [464, 272]
|
||||||
},
|
|
||||||
{
|
|
||||||
"parameters": {},
|
|
||||||
"id": "43c4ee19-6a9d-4b1d-aefa-2c24abe45189",
|
|
||||||
"name": "Error path",
|
|
||||||
"type": "n8n-nodes-base.noOp",
|
|
||||||
"typeVersion": 1,
|
|
||||||
"position": [460, 700]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
"url": "https://webhook.site/e18fe8f9-ec77-4574-a40d-8ae054191e1e",
|
"url": "https://dummyjson.com/todos/1",
|
||||||
"sendBody": true,
|
"sendBody": true,
|
||||||
"specifyBody": "json",
|
"specifyBody": "json",
|
||||||
"jsonBody": "{\n \"q\": \"abc\",\n}",
|
"jsonBody": "{\n \"q\": \"abc\",\n}",
|
||||||
"options": {}
|
"options": {}
|
||||||
},
|
},
|
||||||
"id": "31641920-7f43-473f-ad96-b121122802bb",
|
"id": "c6841eb1-7913-4c8d-8c9d-b88a908125ed",
|
||||||
"name": "HTTP Request",
|
"name": "Invalid JSON Body",
|
||||||
"type": "n8n-nodes-base.httpRequest",
|
"type": "n8n-nodes-base.httpRequest",
|
||||||
"typeVersion": 4.2,
|
"typeVersion": 4.2,
|
||||||
"position": [180, 580],
|
"position": [240, 368],
|
||||||
"alwaysOutputData": false,
|
"alwaysOutputData": false,
|
||||||
"onError": "continueErrorOutput"
|
"onError": "continueErrorOutput"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parameters": {},
|
||||||
|
"id": "21750b7e-c18a-43a5-a068-f8aa85d1cadf",
|
||||||
|
"name": "Success path1",
|
||||||
|
"type": "n8n-nodes-base.noOp",
|
||||||
|
"typeVersion": 1,
|
||||||
|
"position": [464, 656]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parameters": {
|
||||||
|
"url": "https://dummyjson.com/html",
|
||||||
|
"options": {
|
||||||
|
"response": {
|
||||||
|
"response": {
|
||||||
|
"responseFormat": "json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"id": "ae2891f0-1968-4f57-a1a0-87d6f6dab57d",
|
||||||
|
"name": "Invalid JSON Response",
|
||||||
|
"type": "n8n-nodes-base.httpRequest",
|
||||||
|
"typeVersion": 4.2,
|
||||||
|
"position": [240, 752],
|
||||||
|
"alwaysOutputData": false,
|
||||||
|
"onError": "continueErrorOutput"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parameters": {},
|
||||||
|
"id": "baa75f00-e0dd-40b2-b718-1e8311549a05",
|
||||||
|
"name": "Request body error",
|
||||||
|
"type": "n8n-nodes-base.noOp",
|
||||||
|
"typeVersion": 1,
|
||||||
|
"position": [464, 464]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parameters": {},
|
||||||
|
"id": "4733c47f-38c8-44a8-9d77-d9e733777cbf",
|
||||||
|
"name": "Response body error",
|
||||||
|
"type": "n8n-nodes-base.noOp",
|
||||||
|
"typeVersion": 1,
|
||||||
|
"position": [464, 848]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"pinData": {
|
"pinData": {
|
||||||
"Error path": [
|
"Request body error": [
|
||||||
{
|
{
|
||||||
"json": {
|
"json": {
|
||||||
"error": "JSON parameter needs to be valid JSON"
|
"error": "JSON parameter needs to be valid JSON"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"Response body error": [
|
||||||
|
{
|
||||||
|
"json": {
|
||||||
|
"error": "Response body is not valid JSON. Change \"Response Format\" to \"Text\""
|
||||||
|
}
|
||||||
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"connections": {
|
"connections": {
|
||||||
@@ -57,14 +99,19 @@
|
|||||||
"main": [
|
"main": [
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"node": "HTTP Request",
|
"node": "Invalid JSON Body",
|
||||||
|
"type": "main",
|
||||||
|
"index": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"node": "Invalid JSON Response",
|
||||||
"type": "main",
|
"type": "main",
|
||||||
"index": 0
|
"index": 0
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"HTTP Request": {
|
"Invalid JSON Body": {
|
||||||
"main": [
|
"main": [
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@@ -75,7 +122,25 @@
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"node": "Error path",
|
"node": "Request body error",
|
||||||
|
"type": "main",
|
||||||
|
"index": 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"Invalid JSON Response": {
|
||||||
|
"main": [
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"node": "Success path1",
|
||||||
|
"type": "main",
|
||||||
|
"index": 0
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"node": "Response body error",
|
||||||
"type": "main",
|
"type": "main",
|
||||||
"index": 0
|
"index": 0
|
||||||
}
|
}
|
||||||
@@ -87,11 +152,10 @@
|
|||||||
"settings": {
|
"settings": {
|
||||||
"executionOrder": "v1"
|
"executionOrder": "v1"
|
||||||
},
|
},
|
||||||
"versionId": "f445a6e9-818f-4b70-8b4f-e2a68fc5d6e4",
|
"versionId": "c7026310-8c4f-4889-a45b-befebacc7dde",
|
||||||
"meta": {
|
"meta": {
|
||||||
"templateCredsSetupCompleted": true,
|
"instanceId": "27cc9b56542ad45b38725555722c50a1c3fee1670bbb67980558314ee08517c4"
|
||||||
"instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd"
|
|
||||||
},
|
},
|
||||||
"id": "f3rDILaMkFqisP3P",
|
"id": "2Zd3If2j9PglrHri",
|
||||||
"tags": []
|
"tags": []
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user