mirror of
https://github.com/DoctorMcKay/node-steamcommunity.git
synced 2025-01-22 13:46:20 +08:00
Emit chatLogOnFailed on error, and handle fatal errors (fixes #104)
This commit is contained in:
parent
c1b04ee743
commit
a2e26459d9
@ -42,9 +42,17 @@ SteamCommunity.prototype.chatLogon = function(interval, uiMode) {
|
|||||||
var self = this;
|
var self = this;
|
||||||
this.getWebApiOauthToken(function(err, token) {
|
this.getWebApiOauthToken(function(err, token) {
|
||||||
if(err) {
|
if(err) {
|
||||||
|
var fatal = err.message.indexOf('not authorized') != -1;
|
||||||
|
|
||||||
|
if (!fatal) {
|
||||||
|
self.chatState = SteamCommunity.ChatState.LogOnFailed;
|
||||||
|
setTimeout(self.chatLogon.bind(self), 5000);
|
||||||
|
} else {
|
||||||
|
self.chatState = SteamCommunity.ChatState.Offline;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.emit('chatLogOnFailed', err, fatal);
|
||||||
self.emit('debug', "Cannot get oauth token: " + err.message);
|
self.emit('debug', "Cannot get oauth token: " + err.message);
|
||||||
self.chatState = SteamCommunity.ChatState.LogOnFailed;
|
|
||||||
setTimeout(self.chatLogon.bind(self), 5000);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,15 +65,17 @@ SteamCommunity.prototype.chatLogon = function(interval, uiMode) {
|
|||||||
"json": true
|
"json": true
|
||||||
}, function(err, response, body) {
|
}, function(err, response, body) {
|
||||||
if(err || response.statusCode != 200) {
|
if(err || response.statusCode != 200) {
|
||||||
self.emit('debug', 'Error logging into webchat: ' + (err ? err.message : "HTTP error " + response.statusCode));
|
|
||||||
self.chatState = SteamCommunity.ChatState.LogOnFailed;
|
self.chatState = SteamCommunity.ChatState.LogOnFailed;
|
||||||
|
self.emit('chatLogOnFailed', err ? err : new Error("HTTP error " + response.statusCode), false);
|
||||||
|
self.emit('debug', 'Error logging into webchat: ' + (err ? err.message : "HTTP error " + response.statusCode));
|
||||||
setTimeout(self.chatLogon.bind(self), 5000);
|
setTimeout(self.chatLogon.bind(self), 5000);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(body.error != 'OK') {
|
if(body.error != 'OK') {
|
||||||
self.emit('debug', 'Error logging into webchat: ' + body.error);
|
|
||||||
self.chatState = SteamCommunity.ChatState.LogOnFailed;
|
self.chatState = SteamCommunity.ChatState.LogOnFailed;
|
||||||
|
self.emit('chatLogOnFailed', new Error(body.error), false);
|
||||||
|
self.emit('debug', 'Error logging into webchat: ' + body.error);
|
||||||
setTimeout(self.chatLogon.bind(self), 5000);
|
setTimeout(self.chatLogon.bind(self), 5000);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user