Skip to content
This repository was archived by the owner on Apr 17, 2024. It is now read-only.

Commit 001c533

Browse files
committed
Delay retries, improve logging
1 parent ea6c36f commit 001c533

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/lib/msgRoomName.coffee

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@ module.exports = (msg, next, retryCount = 0) ->
1212
})
1313
.header('Authorization', 'Bearer ' + process.env.HUBOT_SLACK_TOKEN)
1414
.get() (err, response, body) ->
15-
if err || response.ok is false || !response.channel
15+
body = JSON.parse(body) if body
16+
if err || response.statusCode isnt 200 || !body?.channel
1617
if retryCount < 3 # Retry up to 3 times
17-
console.warn "Retrying to get channel info for #{msg.message.room}"
18-
console.warn "[Attempt #{retryCount+ 1}]"
19-
module.exports(msg, next, retryCount + 1)
18+
console.warn "Retry [#{retryCount + 1}] to get channel info for #{msg.message.room}"
19+
# Retry after 1 second
20+
setTimeout (-> module.exports(msg, next, retryCount + 1)), 1000
2021
else
21-
console.error "Failed to get channel name after retries for #{msg.message.room}"
22+
error = err || (body)?.error
23+
console.error "Failed to get channel name after #{retryCount} retries for " + \
24+
"#{msg.message.room}. Status: #{response.statusCode}, Error: #{error}"
2225
next null # Signal failure after retries
2326
else
24-
next response.channel.name
27+
next body.channel.name
2528
else
2629
next msg.message.room

0 commit comments

Comments
 (0)