diff options
author | Stan Hu <stanhu@gmail.com> | 2018-07-26 23:05:22 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-07-26 23:05:22 -0700 |
commit | 3f715bb438f81d8847e48d4fa76d1827b2df88eb (patch) | |
tree | 9cacc78580d951fd7378220c06e3766ae9b37e55 /lib | |
parent | 079b490ad2106e83bf315c7f3e9ac5e1d60c0d0c (diff) | |
download | gitlab-ce-3f715bb438f81d8847e48d4fa76d1827b2df88eb.tar.gz |
Consolidate server errors and add specs
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bitbucket_server/client.rb | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/bitbucket_server/client.rb b/lib/bitbucket_server/client.rb index 85c9757339e..15e59f93141 100644 --- a/lib/bitbucket_server/client.rb +++ b/lib/bitbucket_server/client.rb @@ -4,6 +4,18 @@ module BitbucketServer class Client attr_reader :connection + ServerError = Class.new(StandardError) + + SERVER_ERRORS = [SocketError, + OpenSSL::SSL::SSLError, + Errno::ECONNRESET, + Errno::ECONNREFUSED, + Errno::EHOSTUNREACH, + Net::OpenTimeout, + Net::ReadTimeout, + Gitlab::HTTP::BlockedUrlError, + BitbucketServer::Connection::ConnectionError].freeze + def initialize(options = {}) @connection = Connection.new(options) end @@ -13,8 +25,8 @@ module BitbucketServer get_collection(path, :pull_request) end - def activities(project_key, repo, pull_request) - path = "/projects/#{project_key}/repos/#{repo}/pull-requests/#{pull_request}/activities" + def activities(project_key, repo, pull_request_id) + path = "/projects/#{project_key}/repos/#{repo}/pull-requests/#{pull_request_id}/activities" get_collection(path, :activity) end @@ -50,8 +62,10 @@ module BitbucketServer private def get_collection(path, type) - paginator = BitbucketServer::Paginator.new(connection, path, type) + paginator = BitbucketServer::Paginator.new(connection, Addressable::URI.escape(path), type) BitbucketServer::Collection.new(paginator) + rescue *SERVER_ERRORS => e + raise ServerError, e end end end |