mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-04 04:10:33 +03:00
7460076206
refs #9178 - next steps are to A: test if global.Promise works with `got` (see https://github.com/TryGhost/Ghost/pull/8988#issuecomment-351532881) B: re-use request utility everywhere C: request lib requires data/validator, which is dirty
27 lines
756 B
JavaScript
27 lines
756 B
JavaScript
var got = require('got'),
|
|
Promise = require('bluebird'),
|
|
_ = require('lodash'),
|
|
validator = require('../data/validation').validator,
|
|
common = require('./common');
|
|
|
|
module.exports = function request(url, options) {
|
|
if (_.isEmpty(url) || !validator.isURL(url)) {
|
|
return Promise.reject(new common.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);
|
|
});
|
|
});
|
|
};
|