The personal finance app for everyone
Handle ITEM_NOT_FOUND errors on Plaid deletions
Zach Gollwitzer854a21993ac8
diff --git a/app/jobs/destroy_job.rb b/app/jobs/destroy_job.rbindex 74348555..692585de 100644--- a/app/jobs/destroy_job.rb+++ b/app/jobs/destroy_job.rb@@ -3,5 +3,7 @@ class DestroyJob < ApplicationJobdef perform(model)model.destroy+ rescue => e+ model.update!(scheduled_for_deletion: false) # Let's the user try again by resetting the stateendenddiff --git a/app/models/plaid_item.rb b/app/models/plaid_item.rbindex 151b261e..25aa3e18 100644--- a/app/models/plaid_item.rb+++ b/app/models/plaid_item.rb@@ -108,6 +108,15 @@ class PlaidItem < ApplicationRecordprivatedef remove_plaid_itemplaid_provider.remove_item(access_token)+ rescue Plaid::ApiError => e+ json_response = JSON.parse(e.response_body)++ # If the item is not found, that means it was already deleted by the user on their+ # Plaid portal OR by Plaid support. Either way, we're not being billed, so continue+ # with the deletion of our internal record.+ unless json_response["error_code"] == "ITEM_NOT_FOUND"+ raise e+ endend# Plaid returns mutually exclusive arrays here. If the item has made a request for a product,