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

Can't return in promise resolve #18

Closed
flippidippi opened this issue Jun 9, 2017 · 4 comments
Closed

Can't return in promise resolve #18

flippidippi opened this issue Jun 9, 2017 · 4 comments

Comments

@flippidippi
Copy link

flippidippi commented Jun 9, 2017

I'm trying to create a wrapper for superagent with defaults with an authorization header from a callout like:

module.exports = () =>
  new Promise((resolve, reject) => {
    superagent
      .post('https://blah.com/session')
      .send({
        user: 'blah',
        pass: 'blah'
      })
      .then(result => {
        let api = Defaults()
        let base = Prefix('blah')

        api
          .use(base)
          .set({
            'Authorization': result.body.auth_token,
            'Accept': 'application/json'
          })

        resolve(api)
      })
      .catch(err => {
        console.log('api login failed')
        reject(err)
      })
  })

But when I try to use it like below, it successfully gets to the resolve(api) line but never gets to the conn.get line.

api()
  .then(conn => conn.get('/test'))

If I do the same just resolving with superagent without defaults it works. Not sure what's going on 😢

@supertong
Copy link

I got the same problem. Do you have a solution for it already? @flipxfx

@flippidippi
Copy link
Author

flippidippi commented Mar 16, 2018

I switched libraries 🙁

@supertong
Copy link

Thanks for replying @flipxfx . What library did you end up using? I am basically using supertest for my integration testing.
Just in case other people hits this issue. I found a work around for the issue. It was because the object has a .then() function in the prototype.

const request = default(app);
request.then = undefined;

The above code worked around my issue.

@flippidippi
Copy link
Author

flippidippi commented Mar 19, 2018

I use axios, wreck or apollo-client now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants