mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
fix: use correct status code for throwing media error
This commit is contained in:
@@ -633,7 +633,10 @@ export const decodeMediaRetryNode = (node: BinaryNode) => {
|
||||
const errorNode = getBinaryNodeChild(node, 'error')
|
||||
if(errorNode) {
|
||||
const errorCode = +errorNode.attrs.code
|
||||
event.error = new Boom(`Failed to re-upload media (${errorCode})`, { data: errorNode.attrs })
|
||||
event.error = new Boom(
|
||||
`Failed to re-upload media (${errorCode})`,
|
||||
{ data: errorNode.attrs, statusCode: getStatusCodeForMediaRetry(errorCode) }
|
||||
)
|
||||
} else {
|
||||
const encryptedInfoNode = getBinaryNodeChild(node, 'encrypt')
|
||||
const ciphertext = getBinaryNodeChildBuffer(encryptedInfoNode, 'enc_p')
|
||||
@@ -656,4 +659,13 @@ export const decryptMediaRetryData = (
|
||||
const retryKey = getMediaRetryKey(mediaKey)
|
||||
const plaintext = aesDecryptGCM(ciphertext, retryKey, iv, Buffer.from(msgId))
|
||||
return proto.MediaRetryNotification.decode(plaintext)
|
||||
}
|
||||
}
|
||||
|
||||
export const getStatusCodeForMediaRetry = (code: number) => MEDIA_RETRY_STATUS_MAP[code]
|
||||
|
||||
const MEDIA_RETRY_STATUS_MAP = {
|
||||
[proto.MediaRetryNotification.MediaRetryNotificationResultType.SUCCESS]: 200,
|
||||
[proto.MediaRetryNotification.MediaRetryNotificationResultType.DECRYPTION_ERROR]: 412,
|
||||
[proto.MediaRetryNotification.MediaRetryNotificationResultType.NOT_FOUND]: 404,
|
||||
[proto.MediaRetryNotification.MediaRetryNotificationResultType.GENERAL_ERROR]: 418,
|
||||
} as const
|
||||
|
||||
Reference in New Issue
Block a user