Ghost/core/server/utils/request.js
Hannah Wolfe 45fd2d437f Properly return a bluebird promise (#8988)
refs #8980

- ☹️ apparently this is actually the only way
2017-09-07 20:48:20 +07:00

27 lines
751 B
JavaScript

var got = require('got'),
Promise = require('bluebird'),
validator = require('../data/validation').validator,
errors = require('../errors'),
_ = require('lodash');
module.exports = function request(url, options) {
if (_.isEmpty(url) || !validator.isURL(url)) {
return Promise.reject(new errors.InternalServerError({
message: 'URL empty or invalid.',
code: 'URL_MISSING_INVALID',
context: url
}));
}
return new Promise(function (resolve, reject) {
return got(
url,
options
).then(function (response) {
return resolve(response);
}).catch(function (err) {
return reject(err);
});
});
};