Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor middleware #48

Closed
blakeembrey opened this issue Apr 1, 2016 · 0 comments
Closed

Refactor middleware #48

blakeembrey opened this issue Apr 1, 2016 · 0 comments

Comments

@blakeembrey
Copy link
Member

Using before, after and always is kind of tricky and there are a couple of edge-cases. Middleware could be better served with a slightly different paradigm - make middleware just a function call that wraps the request. In a way, the request starts to look more like async middleware. We could probably even re-create Koa-like interfaces.

function retry (next: Function) {
  var ctx = this

  return next()
    .then(function () {
      if (ctx.response.type() === 5) {
        return new popsicle.Request(ctx.options())
      }
    }, function (err) {
      if (err.code === 'EUNAVAILABLE') {
        return new popsicle.Request(ctx.options())
      }

      return Promise.reject(err)
    })
}
blakeembrey added a commit that referenced this issue Apr 5, 2016
blakeembrey added a commit that referenced this issue Apr 5, 2016
blakeembrey added a commit that referenced this issue Apr 14, 2016
blakeembrey added a commit that referenced this issue Apr 14, 2016
blakeembrey added a commit that referenced this issue Apr 14, 2016
blakeembrey added a commit that referenced this issue Apr 14, 2016
blakeembrey added a commit that referenced this issue Apr 14, 2016
blakeembrey added a commit that referenced this issue May 7, 2016
blakeembrey added a commit that referenced this issue May 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant