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:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-12-21 13:53:44 +0300
committerKamil Trzcinski <ayufan@ayufan.eu>2016-12-21 13:53:44 +0300
commit55c61d2e412733b0feefcb5fa33a96e584ffe2bc (patch)
tree7b52b2a60096f04cb67df7452277f34c4f700c30 /lib/mattermost
parent22a0567823e792bd760ced79539a0b2c4bfd8f5e (diff)
Improve API specs
Diffstat (limited to 'lib/mattermost')
-rw-r--r--lib/mattermost/session.rb32
1 files changed, 18 insertions, 14 deletions
diff --git a/lib/mattermost/session.rb b/lib/mattermost/session.rb
index ddfeb88a71f..377cb7b1021 100644
--- a/lib/mattermost/session.rb
+++ b/lib/mattermost/session.rb
@@ -1,11 +1,11 @@
module Mattermost
- class NoSessionError < Error
+ class NoSessionError < Mattermost::Error
def message
'No session could be set up, is Mattermost configured with Single Sign On?'
end
end
- class ConnectionError < Error; end
+ class ConnectionError < Mattermost::Error; end
# This class' prime objective is to obtain a session token on a Mattermost
# instance with SSO configured where this GitLab instance is the provider.
@@ -36,12 +36,12 @@ module Mattermost
def with_session
with_lease do
- raise NoSessionError unless create
+ raise Mattermost::NoSessionError unless create
begin
yield self
rescue Errno::ECONNREFUSED
- raise NoSessionError
+ raise Mattermost::NoSessionError
ensure
destroy
end
@@ -71,19 +71,15 @@ module Mattermost
end
def get(path, options = {})
- self.class.get(path, options.merge(headers: @headers))
- rescue HTTParty::Error => e
- raise Mattermost::ConnectionError.new(e.message)
- rescue Errno::ECONNREFUSED => e
- raise Mattermost::ConnectionError.new(e.message)
+ handle_exceptions do
+ self.class.get(path, options.merge(headers: @headers))
+ end
end
def post(path, options = {})
- self.class.post(path, options.merge(headers: @headers))
- rescue HTTParty::Error => e
- raise Mattermost::ConnectionError.new(e.message)
- rescue Errno::ECONNREFUSED
- raise Mattermost::ConnectionError.new(e.message)
+ handle_exceptions do
+ self.class.post(path, options.merge(headers: @headers))
+ end
end
private
@@ -152,5 +148,13 @@ module Mattermost
lease = ::Gitlab::ExclusiveLease.new(lease_key, timeout: LEASE_TIMEOUT)
lease.try_obtain
end
+
+ def handle_exceptions
+ yield
+ rescue HTTParty::Error => e
+ raise Mattermost::ConnectionError.new(e.message)
+ rescue Errno::ECONNREFUSED
+ raise Mattermost::ConnectionError.new(e.message)
+ end
end
end