0

I am trying to hit an API and to get its response using AXIOS+Java Script+Protractor. I am getting below message in console, can someone please help me?

Code:

const axios = require('axios');
axios.get('jsonplaceholder.typicode.com/todos/1')
    .then(function(response) {
        console.log(response);
    })
    .catch(function(error) {
        console.log(error);
    })
    .finally(function() {
        // always executed 
    });

Please find the below console log:

Error: connect ETIMEDOUT 104.27.135.11:443 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1161:14) errno: 'ETIMEDOUT', code: 'ETIMEDOUT', syscall: 'connect', address: '104.27.135.11', port: 443, config: { url: 'https://reqres.in/api/users/2', method: 'get', headers: { Accept: 'application/json, text/plain, /', 'User-Agent': 'axios/0.19.0' }, transformRequest: [ [Function: transformRequest] ], transformResponse: [ [Function: transformResponse] ], timeout: 0, adapter: [Function: httpAdapter], xsrfCookieName: 'XSRF-TOKEN', xsrfHeaderName: 'X-XSRF-TOKEN', maxContentLength: -1, validateStatus: [Function: validateStatus], data: undefined }, request: Writable { _writableState: WritableState { objectMode: false, highWaterMark: 16384, finalCalled: false, needDrain: false, ending: false, ended: false, finished: false, destroyed: false, decodeStrings: true, defaultEncoding: 'utf8', length: 0, writing: false, corked: 0, sync: true, bufferProcessing: false, onwrite: [Function: bound onwrite], writecb: null, writelen: 0, bufferedRequest: null, lastBufferedRequest: null, pendingcb: 0, prefinished: false, errorEmitted: false, emitClose: true, bufferedRequestCount: 0, corkedRequestsFree: [Object] }, writable: true, _events: { response: [Function: handleResponse], error: [Function: handleRequestError] }, _eventsCount: 2, _maxListeners: undefined, _options: { protocol: 'https:', maxRedirects: 21, maxBodyLength: 10485760, path: '/api/users/2', method: 'GET', headers: [Object], agent: undefined, auth: undefined, hostname: 'reqres.in', port: null, nativeProtocols: [Object], pathname: '/api/users/2' }, _redirectCount: 0, _redirects: [], _requestBodyLength: 0, _requestBodyBuffers: [], _onNativeResponse: [Function], _currentRequest: ClientRequest { _events: [Object], _eventsCount: 6, _maxListeners: undefined, output: [], outputEncodings: [], outputCallbacks: [], outputSize: 0, writable: true, _last: true, chunkedEncoding: false, shouldKeepAlive: false, useChunkedEncodingByDefault: false, sendDate: false, _removedConnection: false, _removedContLen: false, _removedTE: false, _contentLength: 0, _hasBody: true, _trailer: '', finished: true, _headerSent: true, socket: [TLSSocket], connection: [TLSSocket], _header: 'GET /api/users/2 HTTP/1.1\r\nAccept: application/json, text/plain, /\r\nUser-Agent: axios/0.19.0\r\nHost: reqres.in\r\nConnection: close\r\n\r\n', _onPendingData: [Function: noopPendingOutput], agent: [Agent], socketPath: undefined, timeout: undefined, method: 'GET', path: '/api/users/2', _ended: false, res: null, aborted: undefined, timeoutCb: null, upgradeOrConnect: false, parser: null, maxHeadersCount: null, _redirectable: [Circular], [Symbol(isCorked)]: false, [Symbol(outHeadersKey)]: [Object] }, _currentUrl: 'https://reqres.in/api/users/2' }, response: undefined, isAxiosError: true, toJSON: [Function] }

4
  • please add some code and more information so that the community can help you out. For instance, What code you ran that gave this error ? Commented Dec 7, 2019 at 16:28
  • Please find the below code which i have used Commented Dec 7, 2019 at 16:46
  • const axios = require('axios'); axios.get('jsonplaceholder.typicode.com/todos/1') .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); }) .finally(function () { // always executed }); Commented Dec 7, 2019 at 16:47
  • @DivyaReddy Is your response logged ? for the first then Commented Dec 9, 2019 at 6:22

1 Answer 1

0

The reason for this ETIMEDOUT error might be some proxy in front of this endpoint. If that is the reason, then you should modify your request config by passing the proxy host and port along with the endpoint URL.

Sign up to request clarification or add additional context in comments.

3 Comments

Modified the config request with below proxy exports.config = { // seleniumAddress: 'localhost:4444/wd/hub', directconnect : "true", capabilities: { browserName: 'firefox', "proxy": { "host": "http:myorganizationproxy.com", "port": 80 } }, specs: ['test.js'], };
Getting below message in console [05:03:12] I/local - Selenium standalone server started at 51.19.137.62:54871/wd/hub [05:03:15] E/launcher - Unable to create session from {
Is this the axios config where you set the proxy? I think it's not. You should configure your axios instance. I now see that I wasn't very clear about that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.