1

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;
HydroXide
  • 11
  • 3
  • According to [MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/504): "a 504 error is usually not something you can fix, but requires a fix by the web server or the proxies you are trying to get access through." Do you have access to the web server you're working with? – Kevin Jul 27 '17 at 19:38
  • @Kevin That's what we thought but it was working up until recently and the person who created it has left with the latest version. – HydroXide Jul 27 '17 at 19:42
  • Maybe it's because you're sending a POST request with a content length of 99, and content type of json, but the body of the request is empty. (Unless it was just redacted for the question) – J. Titus Jul 27 '17 at 19:43
  • @HydroXide by "left with the latest version", do you mean that they took the web server access that you were using? – Kevin Jul 27 '17 at 19:43
  • @J.Titus it is set to JSON as we are expecting to receive a JSON back - i added an example of using the request – HydroXide Jul 27 '17 at 20:04
  • @Kevin Yes, he took the latest version of the ServerRequest – HydroXide Jul 27 '17 at 20:06
  • @Kevin no we don't have access to the server – HydroXide Jul 27 '17 at 20:13
  • @HydroXide Unfortunately, that means you'll need to set one up yourself. Without access to the web server, you can't make any calls to it. – Kevin Jul 28 '17 at 13:21

0 Answers0