Centralize sdk_object_to_hash logic in DataHelpers module and update all references for improved reusability and consistency. Add error handling for partial and failed SnapTrade account linking. (#741)

Co-authored-by: luckyPipewrench <luckypipewrench@proton.me>
This commit is contained in:
LPW
2026-01-22 16:19:44 -05:00
committed by GitHub
parent bf76d6b88d
commit 9858b36dc7
6 changed files with 41 additions and 52 deletions

View File

@@ -215,10 +215,23 @@ class SnaptradeItemsController < ApplicationController
# Trigger sync to process the newly linked accounts
# Always queue the sync - if one is running, this will run after it finishes
@snaptrade_item.sync_later
redirect_to accounts_path, notice: t(".success", count: linked_count, default: "Successfully linked #{linked_count} account(s).")
if errors.any?
# Partial success - some linked, some failed
redirect_to accounts_path, notice: t(".partial_success", linked: linked_count, failed: errors.size,
default: "Linked #{linked_count} account(s). #{errors.size} failed to link.")
else
redirect_to accounts_path, notice: t(".success", count: linked_count, default: "Successfully linked #{linked_count} account(s).")
end
else
redirect_to setup_accounts_snaptrade_item_path(@snaptrade_item),
alert: t(".no_accounts", default: "No accounts were selected for linking.")
if errors.any?
# All failed
redirect_to setup_accounts_snaptrade_item_path(@snaptrade_item),
alert: t(".link_failed", default: "Failed to link accounts: %{errors}", errors: errors.first)
else
redirect_to setup_accounts_snaptrade_item_path(@snaptrade_item),
alert: t(".no_accounts", default: "No accounts were selected for linking.")
end
end
end