Skip to content

Commit 04fa9c6

Browse files
committed
apply original format
1 parent 7d2a0b5 commit 04fa9c6

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

index.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@
77
* MIT Licensed
88
*
99
*/
10-
var request = require('request');
11-
var _ = require('fg-lodash');
10+
var request = require('request');
11+
var _ = require('fg-lodash');
1212
var Cancelable = require('cancelable');
1313

1414
var RETRIABLE_ERRORS = ['ECONNRESET', 'ENOTFOUND', 'ESOCKETTIMEDOUT', 'ETIMEDOUT', 'ECONNREFUSED', 'EHOSTUNREACH', 'EPIPE'];
1515

16-
var DEFAULTS = {
17-
maxAttempts: 5, // try 5 times
16+
var DEFAULTS = {
17+
maxAttempts: 5, // try 5 times
1818
retryDelay: 5000, // wait for 5s before trying again
1919
};
2020

21-
function Request(options, f, maxAttempts, retryDelay) {
21+
function Request(options, f, maxAttempts, retryDelay){
2222
this.maxAttempts = maxAttempts;
23-
this.retryDelay = retryDelay;
24-
this.options = options;
25-
this.f = _.once(f);
26-
this._timeout = null;
27-
this._req = null;
23+
this.retryDelay = retryDelay;
24+
this.options = options;
25+
this.f = _.once(f);
26+
this._timeout = null;
27+
this._req = null;
2828

2929
// expose _req methods from Request
3030
['end', 'on', 'emit', 'once', 'setMaxListeners', 'start', 'removeListener', 'pipe'].forEach(function(methodName) {
@@ -36,11 +36,11 @@ function Request(options, f, maxAttempts, retryDelay) {
3636

3737
Request.request = request;
3838

39-
Request.prototype._tryUntilFail = function() {
39+
Request.prototype._tryUntilFail = function(){
4040
this.maxAttempts--;
4141

42-
this._req = Request.request(this.options, function(err, response, body) {
43-
if (this._isRetriable(err, response) && this.maxAttempts >= 0) {
42+
this._req = Request.request(this.options, function(err, response, body){
43+
if(this._isRetriable(err, response) && this.maxAttempts >= 0){
4444
this._timeout = setTimeout(this._tryUntilFail.bind(this), this.retryDelay);
4545
return;
4646
}
@@ -49,26 +49,26 @@ Request.prototype._tryUntilFail = function() {
4949
}.bind(this));
5050
};
5151

52-
Request.prototype._isRetriable = function(err, response) {
52+
Request.prototype._isRetriable = function(err, response){
5353
// Inspired from https://github.com/geoffreak/request-enhanced/blob/master/src/request-enhanced.coffee#L107
5454
return (err && _.contains(RETRIABLE_ERRORS, err.code)) || (response && 500 <= response.statusCode && response.statusCode < 600);
5555
};
5656

57-
Request.prototype.abort = function() {
58-
if (this._req) {
57+
Request.prototype.abort = function(){
58+
if(this._req){
5959
this._req.abort();
6060
}
6161
clearTimeout(this._timeout);
6262
this.f(new Error('Aborted'));
6363
};
6464

65-
Request.prototype.exposeReqFunction = function(name) {
66-
if (this._req) {
65+
Request.prototype.exposeReqFunction = function(name){
66+
if(this._req){
6767
this._req[name].apply(this._req, Array.prototype.slice.call(arguments, 1)[0]);
6868
}
6969
};
7070

71-
function Factory(options, f) {
71+
function Factory(options, f){
7272
f = _.isFunction(f) ? f : _.noop;
7373
var retry = _(options || {}).defaults(DEFAULTS).pick(Object.keys(DEFAULTS)).value();
7474
var req = new Request(options, f, retry.maxAttempts, retry.retryDelay);
@@ -78,4 +78,4 @@ function Factory(options, f) {
7878

7979
module.exports = Factory;
8080

81-
Factory.Request = Request;
81+
Factory.Request = Request;

0 commit comments

Comments
 (0)