Skip to content

Commit

Permalink
fix: Re-throw errors from octokit (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeepers committed Feb 5, 2018
1 parent 2f3f434 commit 72d6911
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/github.js
Expand Up @@ -29,7 +29,7 @@ async function paginate (octokit, responsePromise, callback = defaultCallback) {

function EnhancedGitHubClient (options) {
const octokit = Octokit(options)
const limiter = new Bottleneck({ maxConcurrent: 1, minTime: 1000 })
const limiter = options.limiter || new Bottleneck({ maxConcurrent: 1, minTime: 1000 })
const logger = options.logger
const noop = () => Promise.resolve()

Expand All @@ -38,6 +38,7 @@ function EnhancedGitHubClient (options) {
const {method, url, headers, ...params} = options
const msg = `GitHub request: ${method} ${url} - ${error.code} ${error.status}`
logger.debug({params}, msg)
throw error
})
octokit.hook.after('request', (result, options) => {
const {method, url, headers, ...params} = options
Expand Down
11 changes: 8 additions & 3 deletions test/github.test.js
Expand Up @@ -11,10 +11,10 @@ describe('EnhancedGitHubClient', () => {
trace: jest.fn()
}

github = new EnhancedGitHubClient({ logger })

// Set a shorter limiter, otherwise tests are _slow_
github.limiter = new Bottleneck({ maxConcurrent: 1, minTime: 1 })
const limiter = new Bottleneck({ maxConcurrent: 1, minTime: 1 })

github = new EnhancedGitHubClient({ logger, limiter })
})

describe('paginate', () => {
Expand Down Expand Up @@ -63,4 +63,9 @@ describe('EnhancedGitHubClient', () => {
expect(spy).toHaveBeenCalledTimes(3)
})
})

test('properly returns 404 responses', () => {
nock('https://api.github.com').get('/user').reply(404, {message: 'nope'})
return expect(github.users.get({})).rejects.toThrow('nope')
})
})

0 comments on commit 72d6911

Please sign in to comment.