mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 00:11:49 +03:00
ac2578b419
refs #9178
27 lines
762 B
JavaScript
27 lines
762 B
JavaScript
var got = require('got'),
|
|
Promise = require('bluebird'),
|
|
validator = require('../data/validation').validator,
|
|
errors = require('../lib/common/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);
|
|
});
|
|
});
|
|
};
|