Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Room.find({topic: topic}) should allowed to return null #291

Closed
lijiarui opened this issue Mar 2, 2017 · 2 comments
Closed

Room.find({topic: topic}) should allowed to return null #291

lijiarui opened this issue Mar 2, 2017 · 2 comments

Comments

@lijiarui
Copy link
Member

lijiarui commented Mar 2, 2017

Now, function public static async find(query: RoomQueryFilter): Promise` , when we cannot get room, it will throw new Error.

source code as follows:

 public static async find(query: RoomQueryFilter): Promise<Room> {
    log.verbose('Room', 'find({ topic: %s })', query.topic)

    const roomList = await Room.findAll(query)
    if (!roomList || roomList.length < 1) {
      throw new Error('no room found')
    }
    const room = roomList[0]
    await room.ready()
    return room
  }

I thought it should return null when we cannot find the room instead of throw error.

@lijiarui
Copy link
Member Author

lijiarui commented Mar 2, 2017

Then I look up into Class Contact, I think

public static async find(query: ContactQueryFilter): Promise<Contact>

it should return null too when we cannot find the contact instead of throw error

@huan
Copy link
Member

huan commented Mar 2, 2017

I agree. PR is welcome.

lijiarui added a commit to lijiarui/wechaty that referenced this issue Mar 2, 2017
huan pushed a commit that referenced this issue Mar 11, 2017
* #291 change throw error to return null

* add jsDoc
huan pushed a commit that referenced this issue Mar 11, 2017
* #291 change throw error to return null

* add jsDoc

* fix room null error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants