I'm trying to code functions following the promise return pattern, this is a generic example of what I'm trying:
var Promise = require('bluebird');
var request = require('request');
var returnPromise = Promise.method(function () {
    request
      .get('http://google.com/img.png')
      .on('response', function(response) {
            if (response.statusCode !== 200)
                throw new Error('Bad request');
            else
                return response.headers;
      })    
});
returnPromise()
    .then(function (headers) {
        console.log(headers);
    })
    .catch(function (err) {
        console.log('Error handling);
    });
However this is not working properly as the error is yet being thrown and not handled. How should this be implemented?
 
     
    