diff --git a/lib/fetch-url.js b/lib/fetch-url.js index 7b3c771..6ab7614 100644 --- a/lib/fetch-url.js +++ b/lib/fetch-url.js @@ -3,15 +3,15 @@ const stripAnsi = require("strip-ansi"); const request = require("request"); -module.exports = (url, service) => { +module.exports = (urlObj, service) => { return new Promise((resolve, reject) => { - if (typeof url == "string") { - url = { url }; + if (typeof urlObj == "string") { + urlObj = { urlObj }; } - url.headers = { "User-Agent": "pr-preview" }; - request(url, function (error, response, body) { + urlObj.headers = { "User-Agent": "pr-preview" }; + request(urlObj, function (error, response, body) { if (error) { - error.data = { request_url: url, service: service }; + error.data = { request_url: urlObj.url, service: service }; reject(error); } else if (response.statusCode >= 400) { var err = new Error(`${ response.statusCode } ${ response.statusMessage }`); @@ -20,7 +20,7 @@ module.exports = (url, service) => { } catch (e) { err.data = { error: stripAnsi(body) }; } - err.data.request_url = url; + err.data.request_url = urlObj.url; err.data.service = service; reject(err); } else { @@ -28,4 +28,4 @@ module.exports = (url, service) => { } }); }); -}; \ No newline at end of file +};