wechaty / wechaty-puppet-padpro

Apache License 2.0
238 stars 64 forks source link

Wechaty process.exit(1) if token is not valid #1811 #157

Open andriipustovoit opened 5 years ago

andriipustovoit commented 5 years ago

In Nodejs application, I want to start multiple Wechaty PuppetPadpro bot instances dynamically based on an HTTP request. A token for a new instance of Wechaty bot is passed along with the request. But if for some reason not a valid token is passed to Wechaty bot, library prints error and calls process process.exit(-1); which stops the whole Nodejs process with multiple running bot instances. Can somehow I modify Wechaty bot behavior to not perform process.exit(-1); but just print error instead?

I tried to catch errors from bot.start().catch(error => console.log("error")); tried to wrap into Domain to catch errors, but nothing seems to work.

Message that I receive:

  The token is invalid, please use an valid token to access padchat
  If you have question about this, please check out our wiki:
  https://github.com/botorange/wechaty-puppet-padpro/wiki/Buy-Padpro-Token

  你使用的Token是无效的,请你联系我们获取有效Token,详情请参考这个页面:
  https://github.com/botorange/wechaty-puppet-padpro/wiki/%E8%B4%AD%E4%B9%B0token

I expect bot just emits error event on an invalid token, but instead, bot terminates Nodejs process.

P.S. thought about posting question to stack overflow as was recommended but got an error on: Creating the new tag 'wechaty' requires at least 1500 reputation. Try something from the existing tags list instead.

windmemory commented 5 years ago

This logic has been changed from v0.3.6.

Currently wechaty-puppet-padpro does not support one process, multiple wechaty instance well, supporting this use case is in our roadmap, but for now, we don't recommend to do manage bot in this way.

Please try with v0.3.6 or above to see if the issue still exists.