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

Axios gives a 504 error on a Windows VM #1021

Closed
nareshbhatia opened this issue Jul 28, 2017 · 6 comments
Closed

Axios gives a 504 error on a Windows VM #1021

nareshbhatia opened this issue Jul 28, 2017 · 6 comments

Comments

@nareshbhatia
Copy link

#### Summary

The following node.js app using Axios works correctly on Windows and Mac:

var SERVER_URL = 'http://localhost:3000';

var axios = require("axios");

function getBooks() {
    return axios
        .get(SERVER_URL + '/books')
        .then(function(response) {
            return response.data;
        });
}

getBooks()
    .then(function(books) {
        console.log(JSON.stringify(books, null, '    '));
    });

However, if I run it on a Windows 7 or Windows 10 VDI (essentially a virtual machine), it fails with the following error message:

(node:12000) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: Request failed with status code 504

If I replace the axios call with node-fetch, the error goes away and the fetch works. What could be the problem with axios or the way I am using it?

#### Context

  • axios version: v0.16.2
  • Environment: node v6.11.0, windows 7, Windows 10 running in a VDI
@ZhangYiJiang
Copy link

That warning means that the Promise is getting rejected - you should attach a rejection handler to catch it and see what the error is

getBooks()
    .then(...)
    .catch(function(error) { 
        // Do something with error, like logging
    }); 

@nareshbhatia
Copy link
Author

@ZhangYiJiang, thanks for helping out. I am now catching and logging the error returned by axios. It says:

(node:13728) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Converting circular structure to JSON.

Unfortunately, there is no circular structure in the returned JSON. I can hit the same URL from the browser and I get simple objects with two properties (id and name):

[
  {
    "id": "design-patters",
    "name": "Design Patterns"
  },
  ...
]

@nareshbhatia
Copy link
Author

If I put a breakpoint in the catch clause, and inspect the error object, I am getting a 504 error from a gateway inside the firewall. The response is an HTML page displaying the 504 error. I wonder the app it is trying to reach an outside port instead of localhost where the server is running.

@nareshbhatia
Copy link
Author

nareshbhatia commented Aug 5, 2017

Ok, I think I have determined the root cause of this issue, but don't know the solution.

The Windows VM has HTTP proxy settings by setting the environment variable HTTP_PROXY (there is also one called HTTPS_PROXY). For some reason, Axios thinks that it needs to go through the proxy to access http://localhost:3000. Bottom line, it is hitting the proxy, which is returning the 504 error. It is not even hitting the server at http://localhost:3000. If I remove the environment variable, then the problem goes away.

So the question is, should Axios be going through the proxy to access local ports when HTTP_PROXY is set? What is the right way to solve this issue? The HTTP_PROXY variable is required for other applications to work correctly.

BTW, node-fetch seems to be ignoring the HTTP_PROXY variable and works fine even if it is set. I don't know if that's good or bad!

@nareshbhatia
Copy link
Author

After a bit of research, I found that I should set NO_PROXY to exclude hosts that should not go through the proxy. So I set up NO_PROXY as follows:

set NO_PROXY=localhost,127.0.0.*

Unfortunately that doesn't work. Then I stumbled across #434 which has been open since Sep, 2016. Furthermore there is a PR for it, ready to be merged since Dec, 2016: #565. I am baffled why something as important as this has not been merged in 8 months! My faith in Axios is shaken :-(. Please prove me wrong.

@rubennorte
Copy link
Member

We'll review that PR so I'm closing this as duplicate.

@axios axios locked and limited conversation to collaborators May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants