Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jchris
Created December 5, 2013 07:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchris/7801297 to your computer and use it in GitHub Desktop.
Save jchris/7801297 to your computer and use it in GitHub Desktop.
var requestLib = require("request"),
request = requestLib.defaults({
json:true
}, function(uri, options, callback){
var params = requestLib.initParams(uri, options, callback);
return requestLib(params.uri, params.options, function(err, res, body){
// treat bad status codes as errors
if (!err && res.statusCode >= 400) {
params.callback.apply(this, [res.statusCode, res, body]);
} else {
params.callback.apply(this, arguments);
}
})
});
// note: waiting on https://github.com/mikeal/request/pull/727 for this to work with PUT and POST
@jchris
Copy link
Author

jchris commented Dec 5, 2013

note: waiting on request/request#727 for this to work with PUT and POST

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment