The personal finance app for everyone
Add context to plaid sync errors
Zach Gollwitzer9ec94cd1fab3
diff --git a/app/models/family.rb b/app/models/family.rbindex e32c0d78..999e268a 100644--- a/app/models/family.rb+++ b/app/models/family.rb@@ -28,9 +28,13 @@ class Family < ApplicationRecordaccount.sync_data(start_date: start_date)end+ plaid_data = []+plaid_items.each do |plaid_item|- plaid_item.sync_data(start_date: start_date)+ plaid_data << plaid_item.sync_data(start_date: start_date)end++ plaid_dataenddef post_syncdiff --git a/app/models/plaid_item.rb b/app/models/plaid_item.rbindex 881cba17..79087900 100644--- a/app/models/plaid_item.rb+++ b/app/models/plaid_item.rb@@ -35,11 +35,13 @@ class PlaidItem < ApplicationRecorddef sync_data(start_date: nil)update!(last_synced_at: Time.current)- fetch_and_load_plaid_data+ plaid_data = fetch_and_load_plaid_dataaccounts.each do |account|account.sync_data(start_date: start_date)end++ plaid_dataenddef post_sync@@ -53,10 +55,12 @@ class PlaidItem < ApplicationRecordprivatedef fetch_and_load_plaid_data+ data = {}item = plaid_provider.get_item(access_token).itemupdate!(available_products: item.available_products, billed_products: item.billed_products)fetched_accounts = plaid_provider.get_item_accounts(self).accounts+ data[:accounts] = fetched_accounts || []internal_plaid_accounts = fetched_accounts.map do |account|internal_plaid_account = plaid_accounts.find_or_create_from_plaid_data!(account, family)@@ -65,6 +69,7 @@ class PlaidItem < ApplicationRecordendfetched_transactions = safe_fetch_plaid_data(:get_item_transactions)+ data[:transactions] = fetched_transactions || []if fetched_transactionstransaction do@@ -81,6 +86,7 @@ class PlaidItem < ApplicationRecordendfetched_investments = safe_fetch_plaid_data(:get_item_investments)+ data[:investments] = fetched_investments || []if fetched_investmentstransaction do@@ -95,6 +101,7 @@ class PlaidItem < ApplicationRecordendfetched_liabilities = safe_fetch_plaid_data(:get_item_liabilities)+ data[:liabilities] = fetched_liabilities || []if fetched_liabilitiestransaction do@@ -109,6 +116,8 @@ class PlaidItem < ApplicationRecordendendend++ dataenddef safe_fetch_plaid_data(method)diff --git a/app/models/sync.rb b/app/models/sync.rbindex e818b486..6e09fb45 100644--- a/app/models/sync.rb+++ b/app/models/sync.rb@@ -9,7 +9,8 @@ class Sync < ApplicationRecordstart!begin- syncable.sync_data(start_date: start_date)+ data = syncable.sync_data(start_date: start_date)+ update!(data: data) if datacomplete!rescue StandardError => errorfail! error@@ -29,7 +30,10 @@ class Sync < ApplicationRecordenddef fail!(error)- Sentry.capture_exception(error)+ Sentry.capture_exception(error) do |scope|+ scope.set_context("sync", { id: id })+ end+update! status: :failed, error: error.message, last_ran_at: Time.currentendend