Commit 458eff8d authored by Jason Benterou's avatar Jason Benterou
Browse files

Treat any 2xx response as valid

parent f9d2cad3
Loading
Loading
Loading
Loading
+2 −9
Original line number Original line Diff line number Diff line
@@ -2,14 +2,7 @@ var Promise = require('bluebird'),
    request = require('request');
    request = require('request');


function rp(options) {
function rp(options) {
        var statusCodes = {
    var c = {simple: true}, i;
        'GET' : [200],
        'HEAD' : [200],
        'PUT' : [200, 201],
        'POST' : [200, 201],
        'PATCH' : [200, 201],
        'DELETE' : [200, 201]
    }, c = {simple: true}, i;
    if (typeof options === 'string') {
    if (typeof options === 'string') {
        c.uri = options;
        c.uri = options;
        c.method = 'GET';
        c.method = 'GET';
@@ -30,7 +23,7 @@ function rp(options) {
                    options: c,
                    options: c,
                    response: response
                    response: response
                });
                });
            } else if (c.simple && (statusCodes[c.method].indexOf(response.statusCode) === -1)) {
            } else if (c.simple && !(/^2/.test('' + response.statusCode))) {
                reject({
                reject({
                    error: body,
                    error: body,
                    options: c,
                    options: c,
+18 −0
Original line number Original line Diff line number Diff line
@@ -32,6 +32,24 @@ describe('request tests', function () {
            });
            });
    });
    });


    it('should resolve for 201 status code', function (done) {
        rp('http://localhost:4000/201')
            .then(function(){
                done();
            }).catch(function(){
                done(new Error('A 201 response should resolve, not reject'));
            });
    });

    it('should resolve for 204 status code', function (done) {
        rp('http://localhost:4000/204')
            .then(function(){
                done();
            }).catch(function(){
                done(new Error('A 204 response should resolve, not reject'));
            });
    });

    it('should reject for http errors', function(done){
    it('should reject for http errors', function(done){
        rp('http://localhost:1/200')
        rp('http://localhost:1/200')
            .then(function(){
            .then(function(){