Revert "GramJs: Properly handle AUTH_KEY_UNREGISTERED (#1600)"

This reverts commit 166e9e7aab.
This commit is contained in:
Alexander Zinchuk 2021-12-21 20:05:16 +01:00
parent 480c1b76ec
commit 21678f6e83

View File

@ -1,5 +1,3 @@
const { RPCError } = require('../errors');
const MtProtoPlainSender = require('./MTProtoPlainSender');
const MTProtoState = require('./MTProtoState');
const Helpers = require('../Helpers');
@ -422,7 +420,13 @@ class MTProtoSender {
} else if (e instanceof InvalidBufferError) {
// 404 means that the server has "forgotten" our auth key and we need to create a new one.
if (e.code === 404) {
this._handleBadAuthKey();
this._log.warn(`Broken authorization key for dc ${this._dcId}; resetting`);
if (this._updateCallback && this._isMainSender) {
this._updateCallback(new UpdateConnectionState(UpdateConnectionState.broken));
} else if (this._onConnectionBreak && !this._isMainSender) {
// Deletes the current sender from the object
this._onConnectionBreak(this._dcId);
}
} else {
// this happens sometimes when telegram is having some internal issues.
// reconnecting should be enough usually
@ -441,29 +445,12 @@ class MTProtoSender {
try {
await this._processMessage(message);
} catch (e) {
// `RPCError` errors except for 'AUTH_KEY_UNREGISTERED' should be handled by the client
if (e instanceof RPCError) {
if (e.message === 'AUTH_KEY_UNREGISTERED') {
this._handleBadAuthKey();
}
} else {
this._log.error('Unhandled error while receiving data');
this._log.error(e);
}
this._log.error('Unhandled error while receiving data');
this._log.error(e);
}
}
}
_handleBadAuthKey() {
this._log.warn(`Broken authorization key for dc ${this._dcId}; resetting`);
if (this._updateCallback && this._isMainSender) {
this._updateCallback(new UpdateConnectionState(UpdateConnectionState.broken));
} else if (this._onConnectionBreak && !this._isMainSender) {
// Deletes the current sender from the object
this._onConnectionBreak(this._dcId);
}
}
// Response Handlers
/**
@ -570,7 +557,6 @@ class MTProtoSender {
const error = RPCMessageToError(result.error, state.request);
this._send_queue.append(new RequestState(new MsgsAck({ msgIds: [state.msgId] })));
state.reject(error);
throw error;
} else {
try {
const reader = new BinaryReader(result.body);