cujojs / rest

RESTful HTTP client for JavaScript
http://cujojs.com/
Other
1k stars 146 forks source link

Interceptor does not reject on "connection refused" #175

Closed Doogiemuc closed 5 years ago

Doogiemuc commented 7 years ago

(node js 5.7.0 on windows)

When the default rest() client is wraped in an interceptor (that is created with the interceptor factory method), then the wraped client does not reject on "connection refused".

Here is a test case that demonstrates the behviour:

var rest = require('rest');
var interceptor = require('rest/interceptor');

/** Interceptor that SHOULD do nothing. copy&paste from the docs */
var noopInterceptor = interceptor({
    init: function (config) {
        // do stuff with the config
        return config;
    },
    request: function (request, config, meta) {
        // do stuff with the request
        return request;
    },
    response: function (response, config, meta) {
        // do stuff with the response
        return response;
    },
    success: function (response, config, meta) {
        // do stuff with the response
        return response;
    },
    error: function (response, config, meta) {
        // do stuff with the response
        return response;
    }
});

/** wrap the default rest client */
var client = rest.wrap(noopInterceptor)

console.log("sendnig request to unknown host")
client('http://unknown:1234/').then(function(response) {
  console.log('Response: ', response);   // this should not be called!!! But it is called.
})
.catch(function (err) {
  console.log("Catch ERROR ", err)   // this would be the expected behaviour
})
Doogiemuc commented 7 years ago

SOLVED: The example in the doc for a noopIntercaptor has a small glitch: An interceptor must return a rejected Promise in its error handler.

See pull request https://github.com/cujojs/rest/pull/176

scothis commented 5 years ago

rest.js is no longer maintained