2017-09-07 14:17:24 +03:00
|
|
|
var got = require('got'),
|
|
|
|
Promise = require('bluebird'),
|
2017-12-12 00:47:46 +03:00
|
|
|
_ = require('lodash'),
|
2017-09-07 14:17:24 +03:00
|
|
|
validator = require('../data/validation').validator,
|
2017-12-14 00:28:43 +03:00
|
|
|
common = require('./common');
|
2017-09-07 14:17:24 +03:00
|
|
|
|
|
|
|
module.exports = function request(url, options) {
|
|
|
|
if (_.isEmpty(url) || !validator.isURL(url)) {
|
2017-12-12 00:47:46 +03:00
|
|
|
return Promise.reject(new common.errors.InternalServerError({
|
2017-09-07 14:17:24 +03:00
|
|
|
message: 'URL empty or invalid.',
|
|
|
|
code: 'URL_MISSING_INVALID',
|
|
|
|
context: url
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2017-09-07 16:48:20 +03:00
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
return got(
|
|
|
|
url,
|
|
|
|
options
|
|
|
|
).then(function (response) {
|
|
|
|
return resolve(response);
|
|
|
|
}).catch(function (err) {
|
|
|
|
return reject(err);
|
|
|
|
});
|
2017-09-07 14:17:24 +03:00
|
|
|
});
|
|
|
|
};
|