ladjs / superagent

Ajax for Node.js and browsers (JS HTTP client). Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.
https://ladjs.github.io/superagent/
MIT License
16.59k stars 1.33k forks source link

superagent.post - Error: connect ECONNREFUSED 127.0.0.1:8080 #1538

Open anil826 opened 4 years ago

anil826 commented 4 years ago

I updated the version of superagent with 0.1.x to 5.x.x but not sure why I am getting this error in my catch block.

{ Error: connect ECONNREFUSED 127.0.0.1:8080
  at Object._errnoException (util.js:1024:11)
  at _exceptionWithHostPort (util.js:1046:20)
  at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 8080,
  response: undefined }
superagent.post(host_url+'/api/v2/users')
      .send({ first_name: 'test',
        email: email,
        last_name:'Test',
        password:"test",
        password2:"test",
        company: 'test',
        is_registeration: true,
        organisation: crypto.randomBytes(18).toString('hex')
      })
      .then(function(error, res){
        expect(error).to.eql(null);
        expect(res).to.exist;
        expect(res.status).to.equal(200);
        admin_id = res.body._id;
        organisation_id = res.body.organisation;
        res.body.should.have.property('personal_email', email.toLowerCase());
        done();
      })
      .catch(function (error) {
          console.log(error);
      });  

I am not sure if I am doing anything wrong I just replace .end to .then and added the .catch block.

anil826 commented 4 years ago

I think the issue is only on Codeship CI locally same code is working fine. So not sure what is the issue here.

chrisrichie25 commented 4 years ago

@anil826 I am having a similar issue locally when using superagent for testing. Couldn't figure out the issue too. Here is the snippet of my text code.

` const chai = require('chai'); const should = chai.should(); const request = require('superagent');

describe('User level Routes', function () { describe("index routes", function () { it("the / route should return a valid html page ", function () { request.get('/').then(function(response){ response.should.not.be.empty(); }).catch(function(error){ throw error; }) }) }) }) `

Running the above gives the following error

Error: connect ECONNREFUSED 127.0.0.1:80 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) { errno: -4078, code: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 80, response: undefined }