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] }
then
– Madhan