Skip to content

Commit

Permalink
Adds error handler for registry errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sachin-sandhu committed Jan 29, 2025
1 parent 1cf9d09 commit 82d45de
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
14 changes: 12 additions & 2 deletions maven/lib/dependabot/maven/update_checker/version_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,18 @@ def fetch_dependency_metadata(repository_details)
rescue URI::InvalidURIError
nil
rescue Excon::Error::Socket, Excon::Error::Timeout,
Excon::Error::TooManyRedirects
raise if central_repo_urls.include?(repository_details["url"])
Excon::Error::TooManyRedirects => e

if central_repo_urls.include?(repository_details["url"])
response_status = response&.status || 0
response_body = if response
"RegistryError: #{response.status} response status with body #{response.body}"
else
"Registry error: #{e.message}"
end

raise RegistryError.new(response_status, response_body)
end

nil
end
Expand Down
12 changes: 12 additions & 0 deletions maven/spec/dependabot/maven/update_checker/version_finder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,18 @@
end
end

context "with an invalid repository url specified" do
let(:dependency_files) { project_dependency_files("invalid_repository_url") }

before do
stub_request(:get, maven_central_metadata_url).to_raise(Excon::Error::Timeout)
end

it "raises a helpful error" do
expect { latest_version_details }.to raise_error(Dependabot::RegistryError)
end
end

context "with a custom repository" do
let(:pom_fixture_name) { "custom_repositories_pom.xml" }

Expand Down

0 comments on commit 82d45de

Please sign in to comment.