提交 92800c28 编写于 作者: L lijiarui 提交者: Huan (李卓桓)

#291 change `throw error` to `return null` (#292)

* #291 change throw error to return null

* add jsDoc
上级 ee01871e
......@@ -348,14 +348,16 @@ export class Contact implements Sayable {
}
/**
* try to find a contact by filter: {name: string | RegExp}
* try to find a contact by filter: {name: string | RegExp} / {alias: string | RegExp}
* @param {ContactQueryFilter} query
* @returns {Promise<Contact | null>} If can find the contact, return Contact, or return null
*/
public static async find(query: ContactQueryFilter): Promise<Contact> {
public static async find(query: ContactQueryFilter): Promise<Contact | null> {
log.verbose('Contact', 'find(%s)', JSON.stringify(query))
const contactList = await Contact.findAll(query)
if (!contactList || !contactList.length) {
throw new Error('find not found any contact')
return null
}
if (contactList.length > 1) {
......
......@@ -498,12 +498,17 @@ export class Room extends EventEmitter implements Sayable {
})
}
public static async find(query: RoomQueryFilter): Promise<Room> {
/**
* try to find a room by filter: {topic: string | RegExp}
* @param {RoomQueryFilter} query
* @returns {Promise<Room | null>} If can find the room, return Room, or return null
*/
public static async find(query: RoomQueryFilter): Promise<Room | null> {
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')
return null
}
const room = roomList[0]
await room.ready()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册