mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
refactor: remove redundant stream:error handling
This commit is contained in:
@@ -6,6 +6,7 @@ import { Logger } from 'pino'
|
||||
import { proto } from '../../WAProto'
|
||||
import { version as baileysVersion } from '../Defaults/baileys-version.json'
|
||||
import { CommonBaileysEventEmitter, ConnectionState, DisconnectReason, WAVersion } from '../Types'
|
||||
import { BinaryNode, getAllBinaryNodeChildren } from '../WABinary'
|
||||
|
||||
const PLATFORM_MAP = {
|
||||
'aix': 'AIX',
|
||||
@@ -273,6 +274,17 @@ const CODE_MAP: { [_: string]: DisconnectReason } = {
|
||||
* Stream errors generally provide a reason, map that to a baileys DisconnectReason
|
||||
* @param reason the string reason given, eg. "conflict"
|
||||
*/
|
||||
export const getErrorCodeFromStreamErrorReason = (reason: string) => {
|
||||
return CODE_MAP[reason] || DisconnectReason.badSession
|
||||
export const getErrorCodeFromStreamError = (node: BinaryNode) => {
|
||||
const [reasonNode] = getAllBinaryNodeChildren(node)
|
||||
let reason = reasonNode?.tag || 'unknown'
|
||||
const statusCode = +(node.attrs.code || CODE_MAP[reason] || DisconnectReason.badSession)
|
||||
|
||||
if(statusCode === DisconnectReason.restartRequired) {
|
||||
reason = 'restart required'
|
||||
}
|
||||
|
||||
return {
|
||||
reason,
|
||||
statusCode
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user