Skip to content

Commit

Permalink
feat: retry github requests
Browse files Browse the repository at this point in the history
  • Loading branch information
christophwitzko committed Jul 7, 2017
1 parent 3f163a9 commit 0b7b35c
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion lib/github.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
const url = require('url')

const _ = require('lodash')
const Github = require('github')
const { promisify } = require('bluebird')
const promiseRetry = require('promise-retry')

function ghRetry (ghapi) {
const httpSend = ghapi.prototype.httpSend
ghapi.prototype.httpSend = function (msg, block, callback) {
const send = promisify(httpSend.bind(this, msg, block))
promiseRetry(retry => {
return send().catch(err => {
const type = err.code || err.message
if (!['ETIMEDOUT', 'ECONNREFUSED', 'ECONNRESET', 'ESOCKETTIMEDOUT'].includes(type)) {
throw err
}

retry(err)
})
}, {
retries: 5,
minTimeout: 3000
})
.then(res => callback(null, res))
.catch(callback)
}
return ghapi
}

const Github = ghRetry(require('github'))

const githubHost = {}

Expand Down

0 comments on commit 0b7b35c

Please sign in to comment.