Reputation: 9511
I'm using: Axios: 0.17.1 Node: 8.0.0
The following standard Node get works fine, but the Axios version does not. Any ideas why?
Node http:
http
.get(`${someUrl}`, response => {
buildResponse(response).then(results => res.send(results));
})
.on('error', e => {
console.error(`Got error: ${e.message}`);
});
Axios:
axios
.get(`${someUrl}`)
.then(function(response) {
buildResponse(response).then(results => res.send(results));
})
.catch(function(error) {
handleError(error, res);
});
I just get a 503 in the catch, with "Request failed with status code 503"
Upvotes: 7
Views: 28332
Reputation: 1485
use withCredentials
property in your request config
which will resolve your issue.
axios
.get(`${someUrl}`, { withCredentials: true })
.then(function(response) {
return buildResponse(response).then(results => res.send(results));
})
.catch(function(error) {
handleError(error, res);
});
Upvotes: 0
Reputation: 573
I think you might forgot to return axios response.
return axios
.get(`${someUrl}`)
.then(function(response) {
return buildResponse(response).then(results => res.send(results));
})
.catch(function(error) {
handleError(error, res);
});
Notice return before axios.get and before buildResponse
Upvotes: 0
Reputation: 9511
The only thing that worked for me was unsetting the proxy:
delete process.env['http_proxy'];
delete process.env['HTTP_PROXY'];
delete process.env['https_proxy'];
delete process.env['HTTPS_PROXY'];
From: Socket hang up when using axios.get, but not when using https.get
Upvotes: 3
Reputation: 3854
It seems that you can pass Proxy details to Axios FYI.
From the docs...
// 'proxy' defines the hostname and port of the proxy server
// Use `false` to disable proxies, ignoring environment variables.
// `auth` indicates that HTTP Basic auth should be used to connect to the proxy, and
// supplies credentials.
// This will set an `Proxy-Authorization` header, overwriting any existing
// `Proxy-Authorization` custom headers you have set using `headers`.
proxy: {
host: '127.0.0.1',
port: 9000,
auth: {
username: 'mikeymike',
password: 'rapunz3l'
}
},
Upvotes: 3