diff --git a/examples/avatars.js b/examples/avatars.js index f5a4178..3c9a78e 100644 --- a/examples/avatars.js +++ b/examples/avatars.js @@ -9,18 +9,15 @@ const UNIQUE_ID = "031100649"; // Discover routing number * Demonstrate how to get avatar associated with uniqueID. */ async function run() { - // Load credentials and initialize the Moov client - const credentials = loadCredentials("./secrets/credentials.json"); - const moov = new Moov(credentials, gotOptionsForLogging); + try { + // Load credentials and initialize the Moov client + const credentials = loadCredentials("./secrets/credentials.json"); + const moov = new Moov(credentials, gotOptionsForLogging); - try - { - const avatar = moov.avatars.get(UNIQUE_ID); - } - catch(err) - { + await moov.avatars.get(UNIQUE_ID); + } catch (err) { console.error("Error: ", err.message); } } -run(); \ No newline at end of file +run(); diff --git a/examples/createTransfer.js b/examples/createTransfer.js index 96a44af..789b133 100644 --- a/examples/createTransfer.js +++ b/examples/createTransfer.js @@ -28,13 +28,15 @@ async function run() { amount: TRANSFER_AMOUNT, }); - try - { - // Select ACH - const sourcePaymentMethodID = sourceOptions.find( + try { + // Select ACH + const sourceOption = sourceOptions.find( (x) => x.paymentMethodType === "ach-debit-fund" - ).paymentMethodID; - + ); + if (!sourceOption) { + throw new Error("No ACH debit fund option available"); + } + const sourcePaymentMethodID = sourceOption.paymentMethodID; // Get destination transfer options given the source transfer option const { destinationOptions } = await moov.transfers.getTransferOptions({ source: { @@ -47,12 +49,16 @@ async function run() { }); // Select ACH standard - const destinationPaymentMethodID = destinationOptions.find( + const destinationOption = destinationOptions.find( (x) => x.paymentMethodType === "ach-credit-standard" - ).paymentMethodID; + ); + if (!destinationOption) { + throw new Error("No ACH credit standard option available"); + } + const destinationPaymentMethodID = destinationOption.paymentMethodID; // Create the transfer - const transfer = await moov.transfers.create({ + await moov.transfers.create({ source: { paymentMethodID: sourcePaymentMethodID, }, @@ -61,9 +67,7 @@ async function run() { }, amount: TRANSFER_AMOUNT, }); - } - catch(err) - { + } catch (err) { // catch an exception you plan to handle, if not allow it to bubble up console.error("Error: ", err.message); }