slack-bot-api icon indicating copy to clipboard operation
slack-bot-api copied to clipboard

Inconsistent error handling

Open cbrunnkvist opened this issue 8 years ago • 0 comments

I invited my bot to a private channel, but no messages are delivered there despite the bot already on the member list. I'm not sure if that is a but in this module or in Slack, but debugging it turned out to be tricky since no error is reported. Here are three variant calls and:

    // Variant 1:
    try {
      bot.postMessageToChannel('background-tasks', 'Hello private channel!', params)
    } catch (e) {
      console.error('no exception thrown :-/', e)
    }

    // Variant 2:

    bot.postMessageToChannel('background-tasks', 'Hello private channel!', params).then(function (status) {
      console.log('why is .then() called even though message failed to send?', status) // status == undefined 
    }).fail(function (err) {
      console.error('no error + why is this called .fail()? Should catch with .catch() :-/', err)
    })

    // Variant 3:
    bot.postMessageToChannel('background-tasks', 'Hello private channel!', params, function (err) {
      console.error('FINALLY we get an error', err) // we see "AssertionError: channel not found"
    })    

cbrunnkvist avatar Jan 05 '17 10:01 cbrunnkvist