Skip to content

Commit

Permalink
Fix URL object being sent to error message
Browse files Browse the repository at this point in the history
Fixes #154
  • Loading branch information
tobie authored Dec 3, 2024
1 parent bd4c8a4 commit 84b3ce3
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/fetch-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }`);
Expand All @@ -20,12 +20,12 @@ 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 {
resolve(body);
}
});
});
};
};

0 comments on commit 84b3ce3

Please sign in to comment.