6

I am trying to get 200 status code in response, but as a result it's ETIMEDOUT. I can't understand, how is it possible that I can grab successful response via postman, but same via node-fetch responding with ETIMEDOUT always. Here is an example of code:

const Resource = {
  get: cb => {
    fetch('https://example.com', {
      method: 'POST',
      headers: {'Content-Type': 'application/x-www-form-urlencoded'},
      body: {...some body...},
    }).then(res => {
      if (res.status !== 200) cb(`Status: ${res.status}, ${res.statusText}`)
      return res.text()
    }).then(data => {
        cb(null, data)
      }).catch((err) => {
       console.log('ERROR: ', err)
      })
  }
}

and here is response:

ERROR: { FetchError: request to https://example.com failed, reason: connect ETIMEDOUT at ClientRequest.<anonymous> (C:\Users\projects\DSSRQ\node_modules\node-fetch\lib\index.js:1393:11) at emitOne (events.js:116:13) at ClientRequest.emit (events.js:211:7) at TLSSocket.socketErrorListener (_http_client.js:387:9) at emitOne (events.js:116:13) at TLSSocket.emit (events.js:211:7) at emitErrorNT (internal/streams/destroy.js:64:8) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9) message: 'request to https://example.com failed, reason: connect ETIMEDOUT', type: 'system', errno: 'ETIMEDOUT', code: 'ETIMEDOUT' }

blindeveloper
  • 101
  • 1
  • 1
  • 5

1 Answers1

4

It looks like it was because of the proxy limitation.

blindeveloper
  • 101
  • 1
  • 1
  • 5
  • 2
    Can you elaborate a little more please? – Ryan Walker Mar 07 '19 at 00:48
  • 1
    Yes sure. The main problem was in proxy restrictions by company in which I was working. In this case you just need to configure your proxy config file with the domain and passwords for being able to run it. At leas it was my solution. – blindeveloper Mar 08 '19 at 09:06