Skip to content

[RFC] We need a better error system #159

@windmemory

Description

@windmemory

Is your feature request related to a problem? Please describe.
Recently we observed more and more limitation pushed out by WeChat. In some cases, connection to WeChat server got kicked out. It would be better that we emit these cases as errors so developers could handle them properly.

Currently all the error messages emitted is an Error instance, only one message on it, so it is really hard to set a solid error type for the error. So here is this issue, I would like to bring this issue up and talk about the design for WechatyError or something else :P

Describe the solution you'd like
We could have a parent error type as WechatyError, then PuppetError extends the parent, then each puppet has its own error class.

How about this design:

class WechatyError extends Error {
  public readonly type: WechatyErrorType
  public readonly message: string
  constructor (
    type: WechatyErrorType,
    message: string,
  ) {
    super()
    this.type = type
    this.message = message
  }
}

Or we could make this parent error as an abstract class, then all the other errors extends this one.

Describe alternatives you've considered
Haven't considered any alternatives...

Additional context
I've implemented one temporary solution in wechaty-puppet-padpro, but that's just a test, you could check it here:
wechaty/wechaty-puppet-padpro@47d8de1

Here is a small piece of code that how I use it:

bot
.on('error', error => {
  const errorMessage = error.message
  const subMessages = errorMessage.split(' ')
  if (subMessages[0] === 'PADPRO_ERROR' && subMessages[1] === 'LOGIN') {
    console.log(`-----------------------------------------------------
    AutoLogin Error:
    type: ${subMessages[2]}
    message: ${subMessages[3]}
    ------------------------------------------------------`)
  }
})
.start()

To be honest, this is ugly, but just treat this as 【抛砖引玉】(don't know how to translate this :P)

Let's make wechaty better and better.

[enhancement]

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions