Amazebot / bbot

An adaptable conversation engine for building bespoke bots.
MIT License
55 stars 2 forks source link

Empty response from request results in Error #108

Open sschueller opened 5 years ago

sschueller commented 5 years ago

When I make a post request to for example a Jenkins build URL it will result in a TypeError: Cannot convert undefined or null to object error since Jenkins will response with an empty body.

return b.bot.request.post(
    'http://jenkins...',
    {}, {
        auth: {
            user: 'blabla',
            pass: 'password'
        }
    }).then((data) => {
    return b.reply('Success');
}).catch((err) => {
    return b.reply('Error: ' + err);
});
timkinnane commented 5 years ago

Thanks for reporting @sschueller - I think it was throwing only due to the log trying to write the keys from response data, of which there were none in your case. I've changed logic and added tests to ensure handling of empty post requests.

I haven't published this change to NPM yet. I am actually working on another feature branch, which will be a new major version and wasn't planning on releasing any more minor 1.x versions, but I can if you need it. New major version will be a couple weeks away. Re-opening this because it was auto-closed by my commit message, but isn't actually resolved until published.

Just FYI, the next version I've deprecated b.reply method which I see you're using. It was not consistent with the approach of specifying all other alternate response methods via .respondVia - so that would then be b.respondVia('reply', 'success'). The only difference between default and reply method is that reply prefixes the message with @user.

sschueller commented 5 years ago

Thanks, I'm working off the source so no need for NPM.