mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-18 07:51:55 +03:00
6f6c8f4521
refs #9178 - avoid importing 4 modules (logging, errors, events and i18n) - simply require common in each file
27 lines
761 B
JavaScript
27 lines
761 B
JavaScript
var got = require('got'),
|
|
Promise = require('bluebird'),
|
|
_ = require('lodash'),
|
|
validator = require('../data/validation').validator,
|
|
common = require('../lib/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);
|
|
});
|
|
});
|
|
};
|