JSPM

  • Created
  • Published
  • Downloads 2609846
  • Score
    100M100P100Q208024F
  • License MIT

Automatic retry plugin for octokit

Package Exports

  • @octokit/plugin-retry

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@octokit/plugin-retry) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

plugin-retry.js

npm Build Status Coverage Status Greenkeeper

Implements request retries for server 4xx/5xx responses except 400, 401, 403 and 404.

Usage

const Octokit = require('@ocotkit/rest')
  .plugin(require('@octokit/plugin-retry'))

const octokit = new Octokit()

// retries request up to 3 times in case of a 500 response
octokit.request('/').catch(error => {
  if (error.request.request.retryCount) {
    console.log(`request failed after ${error.request.request.retryCount} retries`)
  }

  console.error(error)
})

To override the default doNotRetry list:

const octokit = new Octokit({
  retry: {
    doNotRetry: [ /* List of HTTP 4xx/5xx status codes */ ]
  }
})

You can manually ask for retries for any request by passing { request: { retries: numRetries, retryAfter: delayInSeconds }}

octokit.request('/', { request: { retries: 1, retryAfter: 1 } }).catch(error => {
  if (error.request.request.retryCount) {
    console.log(`request failed after ${error.request.request.retryCount} retries`)
  }

  console.error(error)
})

Pass { retry: { enabled: false } } to disable this plugin.

LICENSE

MIT