Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-07-13 08:33:36 +0300
committerStan Hu <stanhu@gmail.com>2018-07-13 08:33:36 +0300
commit15220291ae1752b9e36ad0b2320180614ec37c59 (patch)
tree4365ad78af4a81b524781719379acd9284c61114 /lib/bitbucket_server/connection.rb
parentf85712fb9814170aac631c7c24ca287fe5a0eb04 (diff)
Add spec for BitbucketServer::Connection
Diffstat (limited to 'lib/bitbucket_server/connection.rb')
-rw-r--r--lib/bitbucket_server/connection.rb8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/bitbucket_server/connection.rb b/lib/bitbucket_server/connection.rb
index c5e40a3964c..0e7817fc82e 100644
--- a/lib/bitbucket_server/connection.rb
+++ b/lib/bitbucket_server/connection.rb
@@ -6,6 +6,8 @@ module BitbucketServer
attr_reader :api_version, :base_uri, :username, :token
+ ConnectionError = Class.new(StandardError)
+
def initialize(options = {})
@api_version = options.fetch(:api_version, DEFAULT_API_VERSION)
@base_uri = options[:base_uri]
@@ -19,6 +21,7 @@ module BitbucketServer
query: extra_query)
check_errors!(response)
+
response.parsed_response
end
@@ -29,6 +32,7 @@ module BitbucketServer
body: body)
check_errors!(response)
+
response
end
@@ -37,13 +41,13 @@ module BitbucketServer
def check_errors!(response)
if response.code != 200
error =
- if response.parsed_response
+ if response.parsed_response && response.parsed_response.is_a?(Hash)
sanitize(response.parsed_response.dig('errors', 0, 'message'))
end
message = "Error #{response.code}"
message += ": #{error}" if error
- raise ::BitbucketServer::Error::Unauthorized, message
+ raise ConnectionError, message
end
end