Function not getting called after promisifying Cloudant

13 views
Skip to first unread message

Kopal Kothari

unread,
Dec 22, 2016, 6:42:34 AM12/22/16
to bluebird
I am trying to promisify cloudant function but some how they are not getting called. Here is the code snippet: 

dbGet(dbName) just doesn't get called. Can anyone help why the call doesn't enter in dbGet function.



var Cloudant = require('cloudant');

var Promise = require('bluebird');


module.exports = {

getDbInstance : getDbInstance

}


var cloudant;

var dbGet, dbCreate;


function getDbInstance(dbName, cloudantUrl)

{

return new Promise(function(resolve, reject){

try{

cloudant = Cloudant(cloudantUrl);

// console.log("cloudant ", cloudant);

dbGet = Promise.promisify(cloudant.db.get);

dbCreate = Promise.promisify(cloudant.db.create);

                


                 dbGet(dbName)

.then(function(resp){

console.log('db exists');

}, function(error){

console.log('db does not exists. Creating db ...');

return dbCreate(dbName);

})

.then(function(){

var dbInstance = cloudant.db.use(dbName);

console.log("returning db instance..");

return resolve({statusCode: constants.SUCCESS, body: dbInstance});

})

.catch(function(error){

console.log('INSIDE INNER CATCH');

console.log(error);

return reject({statusCode: constants.INTERNAL_SERVER_ERROR, body: error});

});

               }

catch(error){

console.log('INSIDE CATCH');

console.log(error);

return reject({statusCode: constants.INTERNAL_SERVER_ERROR, body: error});

}

});

Reply all
Reply to author
Forward
0 new messages