Skip to content

Commit

Permalink
chore(CE): Added exception handling for resource builder (#529)
Browse files Browse the repository at this point in the history
Co-authored-by: TivonB-AI2
  • Loading branch information
github-actions[bot] authored Dec 16, 2024
1 parent 3cd8cd6 commit 5e4fa60
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions server/app/controllers/concerns/resource_link_builder.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

module ResourceLinkBuilder
# rubocop:disable Metrics/CyclomaticComplexity
extend ActiveSupport::Concern
def build_link!(resource_type: nil, resource: nil, resource_id: nil)
resource_type ||= controller_name.singularize.capitalize
Expand All @@ -18,6 +19,12 @@ def build_link!(resource_type: nil, resource: nil, resource_id: nil)
else
reports_link(resource_id)
end
rescue StandardError => e
Rails.logger.error({
error_message: e.message,
stack_trace: Rails.backtrace_cleaner.clean(e.backtrace)
}.to_s)
nil
end

private
Expand Down Expand Up @@ -59,4 +66,5 @@ def members_link
def reports_link(resource_id)
"/reports/#{resource_id}"
end
# rubocop:enable Metrics/CyclomaticComplexity
end
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,14 @@
expect(result).to eq("/reports/#{feedback.id}")
end
end

context "when error arises" do
it "return nil" do
result = build_link!(
resource_type: "Catalog"
)
expect(result).to be_nil
end
end
end
end

0 comments on commit 5e4fa60

Please sign in to comment.