diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-12-20 19:11:53 +0100 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-12-20 19:11:53 +0100 |
commit | 61d09a7b15ef9ae2e23359f1afb87b0adbda4dd4 (patch) | |
tree | 1cfeb2ebdd16c9972ad296416a4db48c30cc7637 /lib | |
parent | 0cf23fde7c666b64e6c18a92d29e632f51b00059 (diff) | |
download | gitlab-ce-61d09a7b15ef9ae2e23359f1afb87b0adbda4dd4.tar.gz |
WIP
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mattermost/client.rb | 12 | ||||
-rw-r--r-- | lib/mattermost/session.rb | 16 |
2 files changed, 14 insertions, 14 deletions
diff --git a/lib/mattermost/client.rb b/lib/mattermost/client.rb index d6759eac0d0..6eaaed34063 100644 --- a/lib/mattermost/client.rb +++ b/lib/mattermost/client.rb @@ -29,13 +29,13 @@ module Mattermost def json_response(response) json_response = JSON.parse(response.body) - if response.success? - json_response - elsif json_response['message'] - raise ClientError(json_response['message']) - else - raise ClientError('Undefined error') + unless response.success? + raise ClientError(json_response['message'] || 'Undefined error') end + + json_response + rescue JSON::JSONError => e + raise ClientError('Cannot parse response') end end end diff --git a/lib/mattermost/session.rb b/lib/mattermost/session.rb index e36500d24a3..7a7912d02fc 100644 --- a/lib/mattermost/session.rb +++ b/lib/mattermost/session.rb @@ -3,15 +3,11 @@ module Mattermost class NoSessionError < Error def message - 'No session could be set up, is Mattermost configured with Single Sign on?' + 'No session could be set up, is Mattermost configured with Single Sign On?' end end - class ConnectionError < Error - def message - 'Could not connect. Is Mattermost up?' - end - end + class ConnectionError < 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. @@ -74,12 +70,16 @@ module Mattermost def get(path, options = {}) self.class.get(path, options.merge(headers: @headers)) - rescue Errno::ECONNREFUSED - raise ConnectionError + rescue HTTParty::Error => e + raise ConnectionError(e.message) + rescue Errno::ECONNREFUSED => e + raise ConnectionError(e.message) end def post(path, options = {}) self.class.post(path, options.merge(headers: @headers)) + rescue HTTParty::Error => e + raise ConnectionError(e.message) rescue Errno::ECONNREFUSED raise ConnectionError end |