Skip to content

Callback support broken #175

@johan1252

Description

@johan1252
  • The npm published version of this library does not have this issue as it is still on version 2.2.1
  • The main branch of this library has many issues since Replace request and request-promise with Axios #161 has merged.
    This is mostly related to removal of callback done support in lib/httpClient.js as seen here
    • I agree that this is overall a positive change, however this has caused many issues upstream. As all the other parts of the library still assume done callback is still supported in httpClient.
      An example is lib/athlete.js with:
       athlete.prototype.get = function (args, done) {
        var endpoint = 'athlete'
        return this.client.getEndpoint(endpoint, args, done)
      }
      
      It assumes that done is still supported in getEndpoint which is not the case.
      Additionally athlete.prototype.get should be marked as async now that this.client.getEndpoint is async.
  • Creating this issue to track work to update all lib/ and test/ to move to async/await and remove done callback usage.

Example:

Before (callback):

  • lib/athlete.js:
athlete.prototype.get = function (args, done) {
  var endpoint = 'athlete'
  return this.client.getEndpoint(endpoint, args, done)
}
  • /test/athlete.js
describe('#get()', function () {
  it('should return detailed athlete information about athlete associated to access_token (level 3)', function (done) {
    strava.athlete.get({}, function (err, payload) {
      if (!err) {
        (payload.resource_state).should.be.exactly(3)
      } else {
        console.log(err)
      }

      done()
    })
  })
})

After (async/await):

  • lib/athlete.js:
athlete.prototype.get = async function (args) {
  var endpoint = 'athlete'
  return await this.client.getEndpoint(endpoint, args)
}
  • /test/athlete.js
describe('#get()', function () {
  it('should return detailed athlete information about athlete associated to access_token (level 3)', async () => {
    const response = await strava.athlete.get({})
    response.resource_state.should.be.exactly(3)
  })
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions