Commit b40cf38d authored by Ty Abonil's avatar Ty Abonil
Browse files

Merge branch 'metaraine-master'

merged sugested changes from u/metaraine-master for a better reject object
bumped version to 0.1

Note: this version breaks expectations on reject passing statusCode string from previous versions
parents 12ba8c18 7f0e93b1
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -4,6 +4,16 @@ A Promises/A XHR wrapper for Bluebird and Request

[Bluebird](https://github.com/petkaantonov/bluebird) and [Request](https://github.com/mikeal/request) are pretty awesome, but I found myself using the same design pattern.  This is a simple wrapper that takes in a request options object (or URI string), and returns a chainable promise.  By default, http response codes other than 200 and 201 will cause the promise to be rejected.  This can be over-ridden by setting `options.simple` to `false`.

Note: As of version 0.1, `reject` now passes  an object containing the following:
```js    
    reject({
                    error: body,
                    options: c,
                    response: response,
                    statusCode: response.statusCode
                });
```

## Installation

`npm install request-promise`
+11 −2
Original line number Diff line number Diff line
@@ -24,9 +24,18 @@ function rp(options) {
    return new Promise(function (resolve, reject) {
        request(c, function (error, response, body) {
            if (error) {
                reject(error);
                reject({
                    error: error,
                    options: c,
                    response: response
                });
            } else if (c.simple && (statusCodes[c.method].indexOf(response.statusCode) === -1)) {
                reject(response.statusCode);
                reject({
                    error: body,
                    options: c,
                    response: response,
                    statusCode: response.statusCode
                });
            } else {
                if (c.transform && typeof c.transform === 'function') {
                    resolve(c.transform(body));
+1 −1
Original line number Diff line number Diff line
{
  "name": "request-promise",
  "version": "0.0.4",
  "version": "0.1.0",
  "description": "Promise-based Wrapper for XHR using Request and Bluebird",
  "main": "./lib/rp.js",
  "scripts": {