Skip to content

Commit

Permalink
handle ssl error exception when federated call to a collection
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed May 10, 2024
1 parent 0db56d7 commit 1fcf35a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/ontologies_api_client/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def uri_from_context(object, media_type)
def entry_point(media_type, params = {})
params = { include: @include_attrs, display_links: false, display_context: false}.merge(params)
federated_get(params) do |url|
uri_from_context(top_level_links(url), media_type)
uri_from_context(top_level_links(url), media_type) rescue nil
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/ontologies_api_client/request_federation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def federated_get(params = {}, &link)
begin
HTTP.get(link.call(conn.url_prefix.to_s.chomp('/')), params, connection: conn)
rescue StandardError => e
[OpenStruct.new(errors: "Problem retrieving #{link.call(conn.url_prefix.to_s.chomp('/'))}")]
[OpenStruct.new(errors: "Problem retrieving #{link.call(conn.url_prefix.to_s.chomp('/')) || conn.url_prefix}")]
end
end

Expand Down
11 changes: 11 additions & 0 deletions test/models/test_federation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,15 @@ def test_federated_analytics
analytics = LinkedData::Client::Analytics.last_month
refute_empty analytics.onts
end


def test_federation_ssl_error
WebMock.enable!
WebMock.stub_request(:get, "#{LinkedData::Client.settings.rest_url.chomp('/')}")
.to_raise(Faraday::SSLError)
ontologies_federate_one = LinkedData::Client::Models::Ontology.all(display_links: false, display_context: false, invalidate_cache: true)

refute_nil ontologies_federate_one.first.errors
WebMock.disable!
end
end

0 comments on commit 1fcf35a

Please sign in to comment.