Skip to content

Commit

Permalink
Added user friendly error messages for list methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Rrathinasabapath committed Nov 5, 2020
1 parent 460a6c5 commit 91b0257
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 39 deletions.
39 changes: 20 additions & 19 deletions src/Hyperwallet.js
Expand Up @@ -92,7 +92,7 @@ export default class Hyperwallet {
listUsers(options, callback) {
const LIST_USER_FILTERS = ["clientUserId", "email", "programToken", "status", "verificationStatus"];
if (options && !this.isValidFilter(options, LIST_USER_FILTERS)) {
throw new Error("Invalid Filter");
throw new Error("Invalid Filter. Expected - ".concat(LIST_USER_FILTERS));
}
this.client.doGet("users", options, Hyperwallet.handle204Response(callback));
}
Expand Down Expand Up @@ -234,7 +234,7 @@ export default class Hyperwallet {
}
const LIST_USER_STATUS_TRANSITION_FILTERS = ["transition"];
if (options && !this.isValidFilter(options, LIST_USER_STATUS_TRANSITION_FILTERS)) {
throw new Error("Invalid Filter");
throw new Error("Invalid Filter. Expected - ".concat(LIST_USER_STATUS_TRANSITION_FILTERS));
}
this.client.doGet(`users/${encodeURIComponent(userToken)}/status-transitions`, options, Hyperwallet.handle204Response(callback));
}
Expand Down Expand Up @@ -331,7 +331,7 @@ export default class Hyperwallet {
}
const LIST_PREPAID_CARDS_FILTERS = ["status"];
if (options && !this.isValidFilter(options, LIST_PREPAID_CARDS_FILTERS)) {
throw new Error("Invalid Filter");
throw new Error("Invalid Filter. Expected - ".concat(LIST_PREPAID_CARDS_FILTERS));
}
this.client.doGet(`users/${encodeURIComponent(userToken)}/prepaid-cards`, options, Hyperwallet.handle204Response(callback));
}
Expand Down Expand Up @@ -529,7 +529,7 @@ export default class Hyperwallet {
}
const LIST_PREPAID_CARD_STATUS_TRANSITION_FILTERS = ["transition"];
if (options && !this.isValidFilter(options, LIST_PREPAID_CARD_STATUS_TRANSITION_FILTERS)) {
throw new Error("Invalid Filter");
throw new Error("Invalid Filter. Expected - ".concat(LIST_PREPAID_CARD_STATUS_TRANSITION_FILTERS));
}
this.client.doGet(`users/${encodeURIComponent(userToken)}/prepaid-cards/${encodeURIComponent(prepaidCardToken)}/status-transitions`, options, Hyperwallet.handle204Response(callback));
}
Expand Down Expand Up @@ -607,7 +607,7 @@ export default class Hyperwallet {
}
const LIST_BANK_CARDS_FILTERS = ["status"];
if (options && !this.isValidFilter(options, LIST_BANK_CARDS_FILTERS)) {
throw new Error("Invalid Filter");
throw new Error("Invalid Filter. Expected - ".concat(LIST_BANK_CARDS_FILTERS));
}
this.client.doGet(`users/${encodeURIComponent(userToken)}/bank-cards`, options, Hyperwallet.handle204Response(callback));
}
Expand Down Expand Up @@ -695,7 +695,7 @@ export default class Hyperwallet {
}
const LIST_BANK_CARD_STATUS_TRANSITION_FILTERS = ["transition"];
if (options && !this.isValidFilter(options, LIST_BANK_CARD_STATUS_TRANSITION_FILTERS)) {
throw new Error("Invalid Filter");
throw new Error("Invalid Filter. Expected - ".concat(LIST_BANK_CARD_STATUS_TRANSITION_FILTERS));
}
this.client.doGet(`users/${encodeURIComponent(userToken)}/bank-cards/${encodeURIComponent(bankCardToken)}/status-transitions`, options, Hyperwallet.handle204Response(callback));
}
Expand Down Expand Up @@ -792,7 +792,7 @@ export default class Hyperwallet {
}
const LIST_PAPER_CHECKS_FILTERS = ["status"];
if (options && !this.isValidFilter(options, LIST_PAPER_CHECKS_FILTERS)) {
throw new Error("Invalid Filter");
throw new Error("Invalid Filter. Expected - ".concat(LIST_PAPER_CHECKS_FILTERS));
}
this.client.doGet(`users/${encodeURIComponent(userToken)}/paper-checks`, options, Hyperwallet.handle204Response(callback));
}
Expand Down Expand Up @@ -880,7 +880,7 @@ export default class Hyperwallet {
}
const LIST_PAPER_CHECK_STATUS_TRANSITION_FILTERS = ["transition"];
if (options && !this.isValidFilter(options, LIST_PAPER_CHECK_STATUS_TRANSITION_FILTERS)) {
throw new Error("Invalid Filter");
throw new Error("Invalid Filter. Expected - ".concat(LIST_PAPER_CHECK_STATUS_TRANSITION_FILTERS));
}
this.client.doGet(`users/${encodeURIComponent(userToken)}/paper-checks/${encodeURIComponent(paperCheckToken)}/status-transitions`, options, Hyperwallet.handle204Response(callback));
}
Expand Down Expand Up @@ -932,7 +932,7 @@ export default class Hyperwallet {
listTransfers(options, callback) {
const LIST_TRANSFERS_FILTERS = ["clientTransferId", "sourceToken", "destinationToken"];
if (options && !this.isValidFilter(options, LIST_TRANSFERS_FILTERS)) {
throw new Error("Invalid Filter");
throw new Error("Invalid Filter. Expected - ".concat(LIST_TRANSFERS_FILTERS));
}
this.client.doGet("transfers", options, Hyperwallet.handle204Response(callback));
}
Expand Down Expand Up @@ -1069,7 +1069,7 @@ export default class Hyperwallet {
}
const LIST_PAYPAL_ACCOUNTS_FILTERS = ["status"];
if (options && !this.isValidFilter(options, LIST_PAYPAL_ACCOUNTS_FILTERS)) {
throw new Error("Invalid Filter");
throw new Error("Invalid Filter. Expected - ".concat(LIST_PAYPAL_ACCOUNTS_FILTERS));
}
this.client.doGet(`users/${encodeURIComponent(userToken)}/paypal-accounts`, options, Hyperwallet.handle204Response(callback));
}
Expand Down Expand Up @@ -1167,7 +1167,7 @@ export default class Hyperwallet {
}
const LIST_BANK_ACCOUNTS_FILTERS = ["type", "status"];
if (options && !this.isValidFilter(options, LIST_BANK_ACCOUNTS_FILTERS)) {
throw new Error("Invalid Filter");
throw new Error("Invalid Filter. Expected - ".concat(LIST_BANK_ACCOUNTS_FILTERS));
}
this.client.doGet(`users/${encodeURIComponent(userToken)}/bank-accounts`, options, Hyperwallet.handle204Response(callback));
}
Expand Down Expand Up @@ -1259,7 +1259,7 @@ export default class Hyperwallet {
}
const LIST_BANK_ACCOUNT_STATUS_TRANSITION_FILTERS = ["transition"];
if (options && !this.isValidFilter(options, LIST_BANK_ACCOUNT_STATUS_TRANSITION_FILTERS)) {
throw new Error("Invalid Filter");
throw new Error("Invalid Filter. Expected - ".concat(LIST_BANK_ACCOUNT_STATUS_TRANSITION_FILTERS));
}
this.client.doGet(`users/${encodeURIComponent(userToken)}/bank-accounts/${encodeURIComponent(bankAccountToken)}/status-transitions`, options, Hyperwallet.handle204Response(callback));
}
Expand All @@ -1283,7 +1283,7 @@ export default class Hyperwallet {
}
const LIST_USER_BALANCE_FILTERS = ["currency"];
if (options && !this.isValidFilter(options, LIST_USER_BALANCE_FILTERS)) {
throw new Error("Invalid Filter");
throw new Error("Invalid Filter. Expected - ".concat(LIST_USER_BALANCE_FILTERS));
}
this.client.doGet(`users/${encodeURIComponent(userToken)}/balances`, options, Hyperwallet.handle204Response(callback));
}
Expand Down Expand Up @@ -1370,7 +1370,7 @@ export default class Hyperwallet {
listPayments(options, callback) {
const LIST_PAYMENT_FILTERS = ["clientPaymentId"];
if (options && !this.isValidFilter(options, LIST_PAYMENT_FILTERS)) {
throw new Error("Invalid Filter");
throw new Error("Invalid Filter. Expected - ".concat(LIST_PAYMENT_FILTERS));
}
this.client.doGet("payments", options, Hyperwallet.handle204Response(callback));
}
Expand Down Expand Up @@ -1427,7 +1427,7 @@ export default class Hyperwallet {
}
const LIST_PAYMENT_STATUS_TRANSITION_FILTERS = ["transition"];
if (options && !this.isValidFilter(options, LIST_PAYMENT_STATUS_TRANSITION_FILTERS)) {
throw new Error("Invalid Filter");
throw new Error("Invalid Filter. Expected - ".concat(LIST_PAYMENT_STATUS_TRANSITION_FILTERS));
}

this.client.doGet(`payments/${encodeURIComponent(paymentToken)}/status-transitions`, options, Hyperwallet.handle204Response(callback));
Expand Down Expand Up @@ -1532,7 +1532,7 @@ export default class Hyperwallet {
}
const LIST_TRANSFER_METHOD_CONFIG_FILTERS = ["userToken"];
if (options && !this.isValidFilter(options, LIST_TRANSFER_METHOD_CONFIG_FILTERS)) {
throw new Error("Invalid Filter");
throw new Error("Invalid Filter. Expected - ".concat(LIST_TRANSFER_METHOD_CONFIG_FILTERS));
}
const params = options ? objectAssign({}, options, { userToken }) : { userToken };
this.client.doGet("transfer-method-configurations", params, Hyperwallet.handle204Response(callback));
Expand Down Expand Up @@ -1635,7 +1635,7 @@ export default class Hyperwallet {
listWebhookNotifications(options, callback) {
const LIST_WEBHOOK_NOTIFICATIONS_FILTERS = ["programToken", "type"];
if (options && !this.isValidFilter(options, LIST_WEBHOOK_NOTIFICATIONS_FILTERS)) {
throw new Error("Invalid Filter");
throw new Error("Invalid Filter. Expected - ".concat(LIST_WEBHOOK_NOTIFICATIONS_FILTERS));
}
this.client.doGet("webhook-notifications", options, Hyperwallet.handle204Response(callback));
}
Expand Down Expand Up @@ -1871,7 +1871,7 @@ export default class Hyperwallet {
}
const LIST_VENMO_ACCOUNT_STATUS_TRANSITION_FILTERS = ["transition"];
if (options && !this.isValidFilter(options, LIST_VENMO_ACCOUNT_STATUS_TRANSITION_FILTERS)) {
throw new Error("Invalid Filter");
throw new Error("Invalid Filter. Expected - ".concat(LIST_VENMO_ACCOUNT_STATUS_TRANSITION_FILTERS));
}
this.client.doGet(`users/${encodeURIComponent(userToken)}/venmo-accounts/${encodeURIComponent(venmoAccountToken)}/status-transitions`, options, Hyperwallet.handle204Response(callback));
}
Expand All @@ -1886,6 +1886,7 @@ export default class Hyperwallet {
isValidFilter(inputFilters, listFilters) {
return Object.keys(inputFilters).every(elem => listFilters.includes(elem));
}

//--------------------------------------
// Business StakeHolder
//--------------------------------------
Expand Down Expand Up @@ -1941,7 +1942,7 @@ export default class Hyperwallet {
}
const LIST_BUSINESS_STAKEHOLDERS_FILTERS = ["status", "isBusinessContact", "isDirector", "isUltimateBeneficialOwner"];
if (options && !this.isValidFilter(options, LIST_BUSINESS_STAKEHOLDERS_FILTERS)) {
throw new Error("Invalid Filter");
throw new Error("Invalid Filter. Expected - ".concat(LIST_BUSINESS_STAKEHOLDERS_FILTERS));
}
this.client.doGet(`users/${encodeURIComponent(userToken)}/business-stakeholders`, options, Hyperwallet.handle204Response(callback));
}
Expand Down

0 comments on commit 91b0257

Please sign in to comment.