Files
sure/app/helpers/simplefin_items_helper.rb
LPW 3fe9768d72 Remove SimpleFIN sync errors modal and related routes, methods, and logic. (#365)
- Removed the `errors` modal and its associated view.
- Eliminated references to `errors` route and controller methods.
- Consolidated error handling into the `register_error` method to improve error tracking and de-duplication.
- Enhanced logging and introduced instrumentation for better observability.

Co-authored-by: Josh Waldrep <joshua.waldrep5+github@gmail.com>
2025-11-22 14:08:43 +01:00

42 lines
1.4 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# frozen_string_literal: true
# View helpers for SimpleFin UI rendering
module SimplefinItemsHelper
# Builds a compact tooltip text summarizing sync errors from a stats hash.
# The stats structure comes from SimplefinItem::Importer and Sync records.
# Returns nil when there is nothing meaningful to display.
#
# Example structure:
# {
# "total_errors" => 3,
# "errors" => [ { "name" => "Chase", "message" => "Timeout" }, ... ],
# "error_buckets" => { "auth" => 1, "api" => 2 }
# }
def simplefin_error_tooltip(stats)
return nil unless stats.is_a?(Hash)
total_errors = stats["total_errors"].to_i
return nil if total_errors.zero?
# Build a small, de-duplicated sample of messages with counts
grouped = Array(stats["errors"]).map { |e|
name = (e[:name] || e["name"]).to_s
msg = (e[:message] || e["message"]).to_s
text = name.present? ? "#{name}: #{msg}" : msg
text.strip
}.reject(&:blank?).tally
sample = grouped.first(2).map { |text, count| count > 1 ? "#{text} (×#{count})" : text }.join("")
buckets = stats["error_buckets"] || {}
bucket_text = if buckets.present?
buckets.map { |k, v| "#{k}: #{v}" }.join(", ")
end
parts = [ "Errors: ", total_errors.to_s ]
parts << " (#{bucket_text})" if bucket_text.present?
parts << "#{sample}" if sample.present?
parts.join
end
end