n8n-io / n8n

Free and source-available fair-code licensed workflow automation tool. Easily automate tasks across different services.
https://n8n.io
Other
47.67k stars 7.25k forks source link

Error When HTTP Request Node Gets Empty Response #11283

Open sprankhub opened 1 week ago

sprankhub commented 1 week ago

Bug Description

In HTTP Request node version 4.2, I get the following error when the HTTP response is empty:

TypeError: Cannot read properties of undefined (reading 'data') at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/HttpRequest/V3/HttpRequestV3.node.js:1842:33) at processTicksAndRejections (node:internal/process/task_queues:95:5) at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/Workflow.js:722:19) at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:711:51 at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:1141:20

My current workaround is to enable the "Include Response Headers and Status" option.

To Reproduce

  1. Add an HTTP Request node version 4.2.
  2. Execute an HTTP request with an empty response.
  3. Execute the node.
  4. See above mentioned error.

Expected behavior

No error should occur if the response is empty.

Operating System

Cloud

n8n Version

1.62.6

Node.js Version

Cloud

Database

SQLite (default)

Execution mode

main (default)

Joffcom commented 1 week ago

Hey @sprankhub,

We have created an internal ticket to look into this which we will be tracking as "GHC-325"

Joffcom commented 1 week ago

Hey @sprankhub,

Do you have an example url that returns an empty response? I think the best option here would be if the request has no response throw an error and mention to use the include response headers / status option as our nodes rely on there being data to run.

sprankhub commented 1 week ago

In my case, this is https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-assignee-put. As you can see, it returns HTTP status code 204 No Content. I don't think there should be an error if the response is clearly empty. It is fine that subsequent nodes aren't executed if there is no output data. This can be fixed by using the "Always Output Data" option. However, sibling nodes should still be executed. But due to the current error, the whole execution of the workflow is stopped.

Joffcom commented 1 week ago

What if the response isn't meant to be empty though wouldn't you want to know which is where the error makes sense. If you are expecting no response then we have the options in place to work around that.

sprankhub commented 1 week ago

I wouldn't care too much if there was an error like "The response is empty. If this is expected, use the "Always Output Data" option in the settings". However, this is currently a very hard to understand error. Took me some time to find the root cause :see_no_evil:

Having said that, I'd still argue 204 No Content is a proper response. Since it is specifically meant for showing "the request was okay, but there is no content in the response". I don't think this should result in an error or should stop the workflow. The workflow should be stopped on 4xx response codes, but not 2xx response codes.

Joffcom commented 1 week ago

You are not wrong on a 204 response being valid as it is in the 200 range, I guess the tricky bit for us is we always expect data so we can link up the data. Maybe if it is a 204 we just output the input data 🤔

I will pop a note on the internal ticket so we can think about the safest option, We should fix that error to make it clearer as a quick action.

Joffcom commented 1 day ago

Hey @sprankhub,

We have tried to reproduce this with https://httpbin.org/status/204 and https://httpstat.us/204 but they both appear to be working, In your environment do these 2 urls also fail?