testrail-integration
Version:
60 lines • 1.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.route = void 0;
const got = require("got");
let responseData;
async function route(url, headerOptions, HttpMethod, inputBody, formFlag) {
if (headerOptions == null) {
headerOptions = { Accept: "application/json" };
}
if (inputBody == null) {
inputBody = "";
}
else if (formFlag) {
inputBody = JSON.parse(inputBody);
}
if (HttpMethod == null) {
HttpMethod = "GET"; //default GET method
}
if (formFlag == null) {
formFlag = false;
}
try {
responseData = await got(url, {
headers: headerOptions,
body: inputBody,
form: formFlag,
method: HttpMethod,
retry: 1,
timeout: 15000
}); // Note: Using "any" for the type, since got has a number of variants for the options parameter.
// It would be better to replace the "any" with a more specific type, if that can be determined.
}
catch (error) {
const customError = JSON.parse(JSON.stringify(error));
const message = {
"message": error.message,
"name": customError.name,
"code": customError.code,
"host": customError.host,
"url": customError.url,
"path": customError.path,
"body": JSON.stringify(customError.body, null, " ")
};
if (customError.body && customError.name === "HTTPError") {
try {
JSON.parse(responseData.body);
return responseData = error.response;
}
catch (err) {
throw JSON.stringify(message, null, " ");
}
}
else {
throw JSON.stringify(message, null, " ");
}
}
return responseData;
}
exports.route = route;
//# sourceMappingURL=routes.js.map