Pass response body back to caller for inventory fetching

This commit is contained in:
Alexander Corn 2016-12-13 00:45:38 -05:00
parent 06df0ecd42
commit ab037b1931

View File

@ -47,7 +47,7 @@ SteamCommunity.prototype.httpRequest = function(uri, options, callback, source)
self.request(options, function (err, response, body) { self.request(options, function (err, response, body) {
var hasCallback = !!callback; var hasCallback = !!callback;
var httpError = options.checkHttpError !== false && self._checkHttpError(err, response, callback); var httpError = options.checkHttpError !== false && self._checkHttpError(err, response, callback, body);
var communityError = !options.json && options.checkCommunityError !== false && self._checkCommunityError(body, httpError ? function () {} : callback); // don't fire the callback if hasHttpError did it already var communityError = !options.json && options.checkCommunityError !== false && self._checkCommunityError(body, httpError ? function () {} : callback); // don't fire the callback if hasHttpError did it already
var tradeError = !options.json && options.checkTradeError !== false && self._checkTradeError(body, httpError || communityError ? function () {} : callback); // don't fire the callback if either of the previous already did var tradeError = !options.json && options.checkTradeError !== false && self._checkTradeError(body, httpError || communityError ? function () {} : callback); // don't fire the callback if either of the previous already did
var jsonError = options.json && options.checkJsonError !== false && !body ? new Error("Malformed JSON response") : null; var jsonError = options.json && options.checkJsonError !== false && !body ? new Error("Malformed JSON response") : null;
@ -85,29 +85,29 @@ SteamCommunity.prototype._notifySessionExpired = function(err) {
this.emit('sessionExpired', err); this.emit('sessionExpired', err);
}; };
SteamCommunity.prototype._checkHttpError = function(err, response, callback) { SteamCommunity.prototype._checkHttpError = function(err, response, callback, body) {
if (err) { if (err) {
callback(err); callback(err, response, body);
return err; return err;
} }
if (response.statusCode >= 300 && response.statusCode <= 399 && response.headers.location.indexOf('/login') != -1) { if (response.statusCode >= 300 && response.statusCode <= 399 && response.headers.location.indexOf('/login') != -1) {
err = new Error("Not Logged In"); err = new Error("Not Logged In");
callback(err); callback(err, response, body);
this._notifySessionExpired(err); this._notifySessionExpired(err);
return err; return err;
} }
if (response.statusCode == 403 && response.body && response.body.match(/<div id="parental_notice_instructions">Enter your PIN below to exit Family View.<\/div>/)) { if (response.statusCode == 403 && response.body && response.body.match(/<div id="parental_notice_instructions">Enter your PIN below to exit Family View.<\/div>/)) {
err = new Error("Family View Restricted"); err = new Error("Family View Restricted");
callback(err); callback(err, response, body);
return err; return err;
} }
if (response.statusCode >= 400) { if (response.statusCode >= 400) {
err = new Error("HTTP error " + response.statusCode); err = new Error("HTTP error " + response.statusCode);
err.code = response.statusCode; err.code = response.statusCode;
callback(err); callback(err, response, body);
return err; return err;
} }