Skip to content

Commit

Permalink
add error handling for failed suback requests
Browse files Browse the repository at this point in the history
  • Loading branch information
tsteinholz committed Jun 13, 2024
1 parent 8d5936e commit 944bbf0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/lib/handlers/ack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,26 @@ const handleAck: PacketHandler = (client, packet) => {
client.messageIdProvider.deallocate(messageId)
const granted = packet.granted as number[]
for (let grantedI = 0; grantedI < granted.length; grantedI++) {
if ((granted[grantedI] & 0x80) !== 0) {
const subackRC = granted[grantedI]
if ((subackRC & 0x80) !== 0) {
err = new Error(`Subscribe error: ${ReasonCodes[subackRC]}`)
err.code = subackRC

// suback with Failure status
const topics = client.messageIdToTopic[messageId]
if (topics) {
topics.forEach((topic) => {
delete client['_resubscribeTopics'][topic]
})
}
client['_removeOutgoingAndStoreMessage'](messageId, () => {

Check failure on line 132 in src/lib/handlers/ack.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Function declared in a loop contains unsafe references to variable(s) 'err'
cb(err, packet)
})
}
}
delete client.messageIdToTopic[messageId]
client['_invokeStoreProcessingQueue']()
cb(null, packet)
cb(err, packet)
break
}
case 'unsuback': {
Expand Down

0 comments on commit 944bbf0

Please sign in to comment.