feat: handle stream:errors more gracefully

This commit is contained in:
Adhiraj Singh
2022-04-25 09:11:03 +05:30
parent 9c7d563d7c
commit 211a899ed4
2 changed files with 26 additions and 6 deletions

View File

@@ -252,7 +252,10 @@ const STATUS_MAP: { [_: string]: proto.WebMessageInfo.WebMessageInfoStatus } = {
'read': proto.WebMessageInfo.WebMessageInfoStatus.READ,
'read-self': proto.WebMessageInfo.WebMessageInfoStatus.READ
}
/**
* Given a type of receipt, returns what the new status of the message should be
* @param type type from receipt
*/
export const getStatusFromReceiptType = (type: string | undefined) => {
const status = STATUS_MAP[type]
if(typeof type === 'undefined') {
@@ -261,3 +264,15 @@ export const getStatusFromReceiptType = (type: string | undefined) => {
return status
}
const CODE_MAP: { [_: string]: DisconnectReason } = {
conflict: DisconnectReason.connectionReplaced
}
/**
* 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
}