2

I am using Express.js for my application and I get the error when making a post request to adobe analytics API.

I tried to add server.timeout but it doesn't fix it...

This is the error message:

Error: read ECONNRESET
at exports._errnoException (util.js:1028:11)
at TLSWrap.onread (net.js:572:26) code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read'

This is the code that fails:

  pullClassifications(req) {
    const dfd = q.defer();
    const { username, password, payload } = req;
    const data = wsse({username: username, password: password});
    const wsseHeaders = {'X-WSSE': data.toString({ nonceBase64: true })};
    const options = {
      'method': 'post',
      'headers': wsseHeaders,
      'content-type': 'application/json',
      'body': payload,
      'json': true,
      'url': 'https://api.omniture.com/admin/1.4/rest/?method=ReportSuite.GetClassifications'
    }

    request(options, function(err, response, body) {
      if(response.statusCode == 200) {
        dfd.resolve(body);
      } else {
        dfd.reject({statusCode: response.statusCode, body: body});
      }
    })
    return dfd.promise;
  }

Update:
I tried to post the same request using Postman and it works, returning the response in 630000 ms.

What is the cause of this error and is there any way to fix it?

Valip
  • 4,440
  • 19
  • 79
  • 150

1 Answers1

0

Have you tried adding timeout option in request? Why are you using Q promise library when you could do it using native promises? Old NodeJs version?

https://github.com/request/request#timeouts

    const options = {
      'timeout': 120 * 60 * 1000 //(120 seconds)
      'method': 'post',
      'headers': wsseHeaders,
      'content-type': 'application/json',
      'body': payload,
      'json': true,
      'url': 'https://api.omniture.com/admin/1.4/rest/?method=ReportSuite.GetClassifications'
    }

    request(options, function(err, response, body) {...});
Marco Talento
  • 2,335
  • 2
  • 19
  • 31
  • I tried to add the `timeout` option to request and still not working. I'm not using an old NodeJs version, just the whole project uses Q promise. – Valip Apr 02 '18 at 16:14
  • Doing `timeout: 0` would disable the request timeout? – Valip Apr 02 '18 at 16:19