depoio / node-telegram-bot

Client wrapper for Telegram Bot API (Under heavy development)
MIT License
136 stars 30 forks source link

Handling response error crashes #42

Closed sebastianarena closed 8 years ago

sebastianarena commented 9 years ago

Hi there, me again. I have your library running 24x7 with a couple of bots on a server. Last week I updated to your latest revision and some crashes started to appear. Sure enough are easy to fix. Seems like the response object is null on some cases. Here are two different errors:

First reported issue

TypeError: Cannot read property 'statusCode' of undefined File "/node_modules/node-telegram-bot/lib/Bot.js", line 203, in Request._callback } else if(res.statusCode === 401){ File "/node_modules/request/request.js", line 198, in self.callback self._callback.apply(self, arguments) File "events.js", line 107, in Request.emit File "/node_modules/request/request.js", line 877, in Request.onRequestError self.emit('error', error) File "events.js", line 107, in ClientRequest.emit

Second reported issue TypeError: Cannot read property 'statusCode' of undefined File "/node_modules/node-telegram-bot/lib/Bot.js", line 159, in Request._callback console.log("Failed to set webhook with code" + res.statusCode); File "/node_modules/request/request.js", line 198, in self.callback self._callback.apply(self, arguments) File "events.js", line 107, in Request.emit File "/node_modules/request/request.js", line 877, in Request.onRequestError self.emit('error', error) File "events.js", line 107, in ClientRequest.emit

Any extra help I can provide, let me know!

longstone commented 9 years ago

Would be nice if you can add a extra line to log the specific error object. However, I've commited a workaround here #43

sebastianarena commented 9 years ago

@longstone actually I think the commit you submitted won't fix the problem. The problem is not that statusCode doesn't exist, is that res is undefined. If statusCode is undefined it wouldn't enter the if anyway. I think if (res && ... ) should fix it.

Unfortunately I don't have an error for this. If you manage to emit an error instead of console.log I might be able to track it on the exceptions server.

longstone commented 9 years ago

i've added the line. In my opinion @shernshiou should decid how to handle errors/logging in overall.

shernshiou commented 8 years ago

@kaminoo @longstone sorry, just got back from busy work. will look into it.

sebastianarena commented 8 years ago

@shernshiou I've downloaded the latest repo and tested 24x7 on dev and found this new problem:

node-telegram-bot/lib/Bot.js:232 self.emit('error', 'Unknow error, '+err.stack); ^ TypeError: Cannot read property 'stack' of null

shernshiou commented 8 years ago

@kaminoo can you provide more info?

sebastianarena commented 8 years ago

@shernshiou the only extra thing I know is that this ocurred during a reconnection. The problem seems to be related that the self.emit is not checking if err if actually not null or undefined. Reconnections can happen without errors actually. So it must be that.

shernshiou commented 8 years ago

@kaminoo I need someone to identify the error before I can output more message. As for now, I will put unknown error.

154a302457f4e0657f4947227262d2d642a55fc5