TypeScript
Promise.reject vs. throw

by Benny Neugebauer

private async getAccount(currency: Asset): Promise<coinbase.Account> {
  const accounts: coinbase.Account[] = await this.getAccounts();

  for (let account of accounts) {
    if (account.currency === currency) {
      return Promise.resolve(account);
    }
  }

  const error = new Error(`Cannot find account for currency "${currency}".`);
  return Promise.reject(error);
}

private async getAccount(currency: Asset): Promise<coinbase.Account> {
  const accounts: coinbase.Account[] = await this.getAccounts();

  for (let account of accounts) {
    if (account.currency === currency) {
      return account;
    }
  }

  const error = new Error(`Cannot find account for currency "${currency}".`);
  throw error;
}