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

Modify Function Room.create return type, from Promise<Room> to Promise<Room|null> #616

Closed
lijiarui opened this issue Jun 28, 2017 · 8 comments

Comments

@lijiarui
Copy link
Member

lijiarui commented Jun 28, 2017

Now, function Room.create() return type as follows:

public static create(contactList: Contact[], topic?: string): Promise<Room> {

I suggest it return Promise<boolean> to detect whether it can create room successfully

Related logs as follows:

If it can create room successfully, return as follows:

Bot createDingRoom() new ding room created: %s Room {
  domain: null,
  _events: {},
  _eventsCount: 0,
  _maxListeners: undefined,
  id: '@@356afb5f9c9491eb34158dd1f11b99e136d104c9055106545869cbba1b0fec1c' }

If it cannot create room successfully, throw the following exception:

02:22:13 ERR PuppetWebBridge roomCreate(@ac4db07084d16fe10555569c660e5b8526d162bdc0acca2e93dd72d322f22b4a,@35f68307d4ec6b6e0eabead00e446127) exception: undefined
02:22:13 WARN PuppetWeb roomCreate(@ac4db07084d16fe10555569c660e5b8526d162bdc0acca2e93dd72d322f22b4a,@35f68307d4ec6b6e0eabead00e446127, 网球黑龙江1群) rejected: undefined
02:22:13 ERR Room create() exception: [object Object]
@huan
Copy link
Member

huan commented Jun 28, 2017

Could you explain the pros and cons between the two design?

A good purpose should go with good reasons.

@lijiarui
Copy link
Member Author

lijiarui commented Jun 28, 2017

After I thought more, maybe it return Promise<Room | null> will be better.

If it cannot create a room, we want to get the fail status and don't see more error.

Like Contact.find() we will return Promise<Contact | null> instead of throw Error if it cannot find a contact.

And Like Contact.alais(string) we will return Promise<boolean> instead of throw Error if it cannot alias a contact successfully

@huan
Copy link
Member

huan commented Jun 28, 2017

Yes, that's the right answer after you think more.

Please think more before post question/suggestions in the future, at least explain your ideas with pros and cons in detail.

@huan huan closed this as completed Jun 28, 2017
@lijiarui
Copy link
Member Author

lijiarui commented Jul 1, 2017

But now it returns and throw error, maybe is should return <Room | null> instead of throw error.

@lijiarui lijiarui reopened this Jul 1, 2017
@huan
Copy link
Member

huan commented Jul 1, 2017

I agree your purpose.

Please change the title of this issue to better reflect your purpose, and I'll label it as a enhancement

@lijiarui lijiarui changed the title Modify Function Room.create return type, from Promise<Room> to Promise<boolean> Modify Function Room.create return type, from Promise<Room> to Promise<Room|null> Jul 2, 2017
@huan
Copy link
Member

huan commented Jul 2, 2017

  1. If we can not find a contact by name, it's not an error because the reason will be there's no contact with that name.
  2. However, if we can not create a room, there must be something wrong.

In CASE 1 we should return null, in CASE 2 we should throw an exception.

So my question is: when will null be returned by Room.create() is necessary, and why?

@huan huan removed the enhancement label Jul 2, 2017
@huan
Copy link
Member

huan commented Jul 15, 2017

Close this issue due to inactivity for almost two weeks.

@huan huan closed this as completed Jul 15, 2017
@lijiarui lijiarui reopened this Jul 15, 2017
@huan
Copy link
Member

huan commented Jul 24, 2017

We should not return null.

We are planning to throw an Exception instead.

See also: #683 (comment)

@huan huan closed this as completed Jul 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants