Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP Request with Got throws error and loose the response body when status code is not successful #3082

Closed
smiziara opened this issue Jul 22, 2021 · 0 comments

Comments

@smiziara
Copy link

smiziara commented Jul 22, 2021

Current Behavior

When consuming Rest APIs using the HTTP Request connection, the current implementation with GOT is Throwing errors on non success status codes, that are "normal" with Rest APIs.

So instead of being able to handle the response, GOT throws an error and NodeRed 2 is replacing the payload with a concatenated message, loosing the response. This behavior is different from the previous version.

The current implementation uses a Catch after the GOT call, overriding the response body and the status code, leaving it impossible for the flow to provide a proper treatment.

msg.payload = err.toString() + " : " + url;
msg.statusCode = err.code || (err.response?err.response.statusCode:undefined);
nodeSend(msg);

Expected Behavior

We should be able to handle the output, with the response status code and body, like the previous version.

This behaviour can be changed in GOT but the Option (throwHttpErrors) is not exposed by NodeRed.

Steps To Reproduce

Using the HTTP Request connection, consume any Http endpoint that returns a non success status code, like 400.

Example flow

paste your flow here

Environment

  • Node-RED version: 2.0.2
  • Node.js version: 16.1
  • npm version: 7.16
  • Platform/OS: Windows
  • Browser: Google Chrome
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant