mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-27 17:19:39 +02:00
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.
This commit is contained in:
parent
194dad702d
commit
aebbb9a3c1
1 changed files with 12 additions and 2 deletions
|
@ -62,8 +62,18 @@ class Account < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def institution_domain
|
def institution_domain
|
||||||
return nil unless plaid_account&.plaid_item&.institution_url.present?
|
url_string = plaid_account&.plaid_item&.institution_url
|
||||||
URI.parse(plaid_account.plaid_item.institution_url).host.gsub(/^www\./, "")
|
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
|
end
|
||||||
|
|
||||||
def destroy_later
|
def destroy_later
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue