So we need to send a request but we are recieving error 504 and after spending hours on it we cannot find whats missing or whats wrong. The person who created it has left and we cannot fix it. The full error JSON is here https://pastebin.com/ngumgbEr. Please guide us.
"use strict";
exports.__esModule = true;
var CryptoJS = require("crypto-js");
var Request = require("request-promise-native");
var ServerRequest = (function () {
/**
* Class constructor that takes the request data.
* @param authToken is the authorization token for the API.
* @param data RequestData object.
* @param url that should be accessed in the request.
*/
function ServerRequest(authToken, data, url) {
this.authToken = authToken;
this.data = data;
this.url = url;
if (!this.data.get("ad_id")) {
throw new Error("The given data should contain an ad id.");
}
else {
this.getKeyFromData();
this.generateHash();
}
}
/**
* Does the request to the GameHive servers
* @returns {Promise<Object>} Promise object with request response as a JSON object.
*/
ServerRequest.prototype.doRequest = function () {
var _self = this;
return new Promise(function (resolve) {
//* HTTP request options
var options = {
method: "POST",
url: "https://tt2.gamehivegames.com/" + _self.url +
"?d=android&v=1.7.1&time=" + _self.getCurrentTicks() +
"&dummy=78.82546&s=" + _self.hash,
headers: {
"X-HTTP-Method-Override": "POST",
"Accept": "application/vnd.gamehive.btb4-v1.0+json",
"Authorization": "token " + _self.authToken,
"Content-Type": "application/json; charset=UTF-8",
"Host": "tt2.gamehivegames.com",
"Accept-Encoding": "gzip, identity",
"Connection": "Keep-Alive, TE",
"TE": "identity",
"User-Agent": "bestHTTP",
"Content-Length": "99",
},
body: " "
};
Request(options)
.then(function (body) {
resolve(JSON.parse(body));
})
.catch(err => {
console.error(err);
return err;
});
});
};
The below code is an example of using the above piece of code
exports.__esModule = true;
var ServerRequest_1 = require("./ServerRequest");
var API = (function () {
function API(adId, playerId, authToken) {
this.adId = adId;
this.playerId = playerId;
this.authToken = authToken;
}
API.prototype.getClanContributions = function () {
return __awaiter(this, void 0, void 0, function () {
var requestUrl, requestData, serverRequest, e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
requestUrl = "dungeon/contributions";
requestData = new Map();
requestData.set("ad_id", this.adId);
requestData.set("player_id", this.playerId);
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
serverRequest = new ServerRequest_1.ServerRequest(this.authToken, requestData, requestUrl);
return [4 /*yield*/, serverRequest.doRequest()];
case 2: return [2 /*return*/, _a.sent()];
case 3:
e_1 = _a.sent();
console.log("###" + e_1);
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
}
});
});
};
return API;