From aebbb9a3c1c5d26e04ad95e77202085e1d13abb3 Mon Sep 17 00:00:00 2001 From: Josh Pigford Date: Thu, 1 May 2025 18:52:09 -0500 Subject: [PATCH 1/2] Enhance institution_domain method in Account model - Improved error handling for invalid institution URLs by rescuing URI::InvalidURIError and logging a warning. - Refactored the method to use safe navigation and streamline the URL parsing process. --- app/models/account.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/models/account.rb b/app/models/account.rb index f07b442f..85167e22 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -62,8 +62,18 @@ class Account < ApplicationRecord end def institution_domain - return nil unless plaid_account&.plaid_item&.institution_url.present? - URI.parse(plaid_account.plaid_item.institution_url).host.gsub(/^www\./, "") + url_string = plaid_account&.plaid_item&.institution_url + return nil unless url_string.present? + + begin + uri = URI.parse(url_string) + # Use safe navigation on .host before calling gsub + uri.host&.gsub(/^www\./, "") + rescue URI::InvalidURIError + # Log a warning if the URL is invalid and return nil + Rails.logger.warn("Invalid institution URL encountered for account #{id}: #{url_string}") + nil + end end def destroy_later From 0946a1497a0865185ad943d0d82a21f71e171d31 Mon Sep 17 00:00:00 2001 From: Josh Pigford Date: Thu, 1 May 2025 19:07:50 -0500 Subject: [PATCH 2/2] Add conditional rendering for account links in transfers view - Implemented checks for the existence of accounts before rendering links in the transfers partial. - Added error messaging for missing accounts to improve user feedback and prevent broken links. --- app/views/transfers/_account_links.html.erb | 22 +++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/app/views/transfers/_account_links.html.erb b/app/views/transfers/_account_links.html.erb index 33390b31..738416c6 100644 --- a/app/views/transfers/_account_links.html.erb +++ b/app/views/transfers/_account_links.html.erb @@ -1,7 +1,25 @@ <%# locals: (transfer:, is_inflow: false) %>
<% first_account, second_account = is_inflow ? [transfer.to_account, transfer.from_account] : [transfer.from_account, transfer.to_account] %> - <%= link_to first_account.name, account_path(first_account, tab: "activity"), class: "hover:underline", data: { turbo_frame: "_top" } %> + + <%# Check if first_account exists before creating link %> + <% if first_account %> + <%= link_to first_account.name, account_path(first_account, tab: "activity"), class: "hover:underline", data: { turbo_frame: "_top" } %> + <% else %> + + Data Error: Missing account + + <% end %> + + <%# Use icon helper per conventions %> <%= icon(is_inflow ? "arrow-left" : "arrow-right", size: "sm") %> - <%= link_to second_account.name, account_path(second_account, tab: "activity"), class: "hover:underline", data: { turbo_frame: "_top" } %> + + <%# Check if second_account exists before creating link %> + <% if second_account %> + <%= link_to second_account.name, account_path(second_account, tab: "activity"), class: "hover:underline", data: { turbo_frame: "_top" } %> + <% else %> + + Data Error: Missing account + + <% end %>