lakenen / node-box-view

A node client for the Box View API
MIT License
13 stars 2 forks source link

Method uploadURL is not compatible with Bluebird.promisify #23

Open DominikPalo opened 8 years ago

DominikPalo commented 8 years ago

I'm using your library in an async-await way - with method uploadURL promisified using the Bluebird promisify method :

const boxviewJsonResponse = await Bluebird.promisify<any, string, any>(boxViewClient.documents.uploadURL)(publicUrl, options);

In most cases it works fine, but sometimes it throws an error:

Uncaught exception TypeError: Cannot read property 'uploadURL' of undefined at /.../node_modules/box-view/index.js:499:21 at tryOnTimeout (timers.js:224:11) at Timer.listOnTimeout (timers.js:198:5)

I rewrote it as:

const deferred = Bluebird.defer<any>();
boxViewClient.documents.uploadURL(publicUrl, options, (err: any, jsonData: any, httpResponse: any) => {
    if (err) {
        deferred.reject(err);
    }
    else {
        deferred.resolve(jsonData);
    }
});

const boxviewJsonResponse = await deferred.promise;

now it works fine, but it would be nice to have this method fully compatible also with the first (promisify) approach.