TypeScript
async/await

by Benny Neugebauer

public createConversation(name: string, users: string[] = []): Promise<Conversation> {
  if (this.apiClient.context && !users.includes(this.apiClient.context.userId)) {
    users = users.concat([this.apiClient.context.userId]);
  }

  const newConversation: NewConversation = {
    name,
    users
  };

  return this.apiClient.conversation.api.postConversation(newConversation).catch(error => {
    if (error && error.response) {
      throw BackendErrorMapper.map(error.response.data as BackendError);
    }
    throw error;
  });
}

public async createConversation(name: string, users: string[] = []): Promise<Conversation> {
  if (this.apiClient.context && !users.includes(this.apiClient.context.userId)) {
    users = users.concat([this.apiClient.context.userId]);
  }

  const newConversation: NewConversation = {
    name,
    users
  };

  try {
    const conversation = await this.apiClient.conversation.api.postConversation(newConversation);
    return conversation;
  } catch (error) {
    if (error && error.response) {
      throw BackendErrorMapper.map(error.response.data as BackendError);
    }
    throw error;
  }
}