ctimmerm / axios-mock-adapter

Axios adapter that allows to easily mock requests
MIT License
3.44k stars 244 forks source link

.timeout() returns ECONNREFUSED instead of ECONNABORTED #216

Closed nfriend closed 4 years ago

nfriend commented 5 years ago

According to the README:

// Returns a failed promise with Error with code set to 'ECONNABORTED'
mock.onGet('/users').timeout();

However, I'm seeing an err.code of ECONNREFUSED instead. Here's the err object that's given to my .catch() block:

{
  "message":"connect ECONNREFUSED 127.0.0.1:80",
  "name":"Error",
  "stack":"Error: connect ECONNREFUSED 127.0.0.1:80\n    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1056:14)",
  "config":{
    "url":"/navigation-err",
    "method":"get",
    "headers":{
      "Accept":"application/json, text/plain, */*",
      "X-CSRF-Token":{

      },
      "X-Requested-With":"XMLHttpRequest",
      "User-Agent":"axios/0.19.0"
    },
    "transformRequest":[
      null
    ],
    "transformResponse":[
      null
    ],
    "timeout":0,
    "xsrfCookieName":"XSRF-TOKEN",
    "xsrfHeaderName":"X-XSRF-TOKEN",
    "maxContentLength":-1
  },
  "code":"ECONNREFUSED"
}

Which code is expected from .timeout()?

ctimmerm commented 4 years ago

The code will be ECONNABORTED: https://github.com/ctimmerm/axios-mock-adapter/blob/master/src/index.js#L138-L148

If it's ECONNREFUSED it's not coming from axios-mock-adapter.

zdelagrange commented 4 years ago

I am experiencing the same behavior, but only with POST, PUT, DELETE.

GET works exactly how I expect it to. Even if it isn't related to the package, are there any hints as to where it would be coming from?

Ethaan commented 3 years ago

@zdelagrange find a solution? only happens when mocking POST