From 3f715bb438f81d8847e48d4fa76d1827b2df88eb Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Thu, 26 Jul 2018 23:05:22 -0700 Subject: Consolidate server errors and add specs --- lib/bitbucket_server/client.rb | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'lib/bitbucket_server') 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 -- cgit v1.2.3