diff options
author | Stan Hu <stanhu@gmail.com> | 2018-07-12 22:33:36 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-07-12 22:33:36 -0700 |
commit | 15220291ae1752b9e36ad0b2320180614ec37c59 (patch) | |
tree | 4365ad78af4a81b524781719379acd9284c61114 /lib/bitbucket_server | |
parent | f85712fb9814170aac631c7c24ca287fe5a0eb04 (diff) | |
download | gitlab-ce-15220291ae1752b9e36ad0b2320180614ec37c59.tar.gz |
Add spec for BitbucketServer::Connection
Diffstat (limited to 'lib/bitbucket_server')
-rw-r--r-- | lib/bitbucket_server/client.rb | 1 | ||||
-rw-r--r-- | lib/bitbucket_server/connection.rb | 8 | ||||
-rw-r--r-- | lib/bitbucket_server/error/unauthorized.rb | 5 |
3 files changed, 6 insertions, 8 deletions
diff --git a/lib/bitbucket_server/client.rb b/lib/bitbucket_server/client.rb index 49654e45226..802fe7953ce 100644 --- a/lib/bitbucket_server/client.rb +++ b/lib/bitbucket_server/client.rb @@ -18,7 +18,6 @@ module BitbucketServer def repo(project, repo_name) parsed_response = connection.get("/projects/#{project}/repos/#{repo_name}") - # XXXX TODO Handle failure BitbucketServer::Representation::Repo.new(parsed_response) end 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 diff --git a/lib/bitbucket_server/error/unauthorized.rb b/lib/bitbucket_server/error/unauthorized.rb deleted file mode 100644 index 96ed469e913..00000000000 --- a/lib/bitbucket_server/error/unauthorized.rb +++ /dev/null @@ -1,5 +0,0 @@ -module BitbucketServer - module Error - Unauthorized = Class.new(StandardError) - end -end |