mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Moved message parsing logic outside try/catch
This commit is contained in:
@@ -299,11 +299,21 @@ export class WAConnection extends Base {
|
||||
this.lastSeen = new Date(parseInt(timestamp))
|
||||
this.emit ('received-pong')
|
||||
} else {
|
||||
let messageTag: string
|
||||
let json: any
|
||||
try {
|
||||
const [messageTag, json] = Utils.decryptWA (message, this.authInfo?.macKey, this.authInfo?.encKey, new Decoder())
|
||||
if (this.shouldLogMessages) this.messageLog.push ({ tag: messageTag, json: JSON.stringify(json), fromMe: false })
|
||||
const dec = Utils.decryptWA (message, this.authInfo?.macKey, this.authInfo?.encKey, new Decoder())
|
||||
messageTag = dec[0]
|
||||
json = dec[1]
|
||||
} catch (error) {
|
||||
this.logger.error ({ error }, `encountered error in decrypting message, closing: ${error}`)
|
||||
|
||||
if (!json) { return }
|
||||
if (this.state === 'open') this.unexpectedDisconnect (DisconnectReason.badSession)
|
||||
else this.rejectPendingConnection (new Error(DisconnectReason.badSession))
|
||||
}
|
||||
|
||||
if (this.shouldLogMessages) this.messageLog.push ({ tag: messageTag, json: JSON.stringify(json), fromMe: false })
|
||||
if (!json) return
|
||||
|
||||
if (this.logger.level === 'trace') {
|
||||
this.logger.trace(messageTag + ', ' + JSON.stringify(json))
|
||||
@@ -340,12 +350,6 @@ export class WAConnection extends Base {
|
||||
if (this.logger.level === 'debug') {
|
||||
this.logger.debug({ unhandled: true }, messageTag + ',' + JSON.stringify(json))
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.error ({ error }, `encountered error in decrypting message, closing: ${error}`)
|
||||
|
||||
if (this.state === 'open') this.unexpectedDisconnect (DisconnectReason.badSession)
|
||||
else this.rejectPendingConnection (new Error(DisconnectReason.badSession))
|
||||
}
|
||||
}
|
||||
}
|
||||
/** Send a keep alive request every X seconds, server updates & responds with last seen */
|
||||
|
||||
Reference in New Issue
Block a user