mirror of
https://github.com/we-promise/sure.git
synced 2026-04-07 14:31:25 +00:00
Handle ITEM_NOT_FOUND errors on Plaid deletions
This commit is contained in:
@@ -3,5 +3,7 @@ class DestroyJob < ApplicationJob
|
|||||||
|
|
||||||
def perform(model)
|
def perform(model)
|
||||||
model.destroy
|
model.destroy
|
||||||
|
rescue => e
|
||||||
|
model.update!(scheduled_for_deletion: false) # Let's the user try again by resetting the state
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -108,6 +108,15 @@ class PlaidItem < ApplicationRecord
|
|||||||
private
|
private
|
||||||
def remove_plaid_item
|
def remove_plaid_item
|
||||||
plaid_provider.remove_item(access_token)
|
plaid_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
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Plaid returns mutually exclusive arrays here. If the item has made a request for a product,
|
# Plaid returns mutually exclusive arrays here. If the item has made a request for a product,
|
||||||
|
|||||||
Reference in New Issue
Block a user