Commit b3de65bc authored by Z.J. van de Weg's avatar Z.J. van de Weg

Update #list_teams to propagate errors

parent 8bcc911b
...@@ -34,10 +34,7 @@ class Projects::MattermostsController < Projects::ApplicationController ...@@ -34,10 +34,7 @@ class Projects::MattermostsController < Projects::ApplicationController
end end
def teams def teams
@teams ||= begin @teams, @teams_error_message = @service.list_teams(current_user)
teams, error_message = @service.list_teams(current_user)
error_message ? error_message : teams
end
end end
def service def service
......
...@@ -28,10 +28,10 @@ class MattermostSlashCommandsService < ChatSlashCommandsService ...@@ -28,10 +28,10 @@ class MattermostSlashCommandsService < ChatSlashCommandsService
[false, e.message] [false, e.message]
end end
def list_teams(user) def list_teams(current_user)
Mattermost::Team.new(user).all [Mattermost::Team.new(current_user).all, nil]
rescue Mattermost::Error rescue Mattermost::Error => e
[] [[], e.message]
end end
private private
......
= content_for :flash_message do - if @teams_error_message
.alert.alert-danger= @teams if @teams.is_a?(String) = content_for :flash_message do
.alert.alert-danger= @teams_error_message
%p %p
You aren’t a member of any team on the Mattermost instance at You aren’t a member of any team on the Mattermost instance at
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
.inline.pull-right .inline.pull-right
= custom_icon('mattermost_logo', size: 48) = custom_icon('mattermost_logo', size: 48)
%h3 Install Mattermost Command %h3 Install Mattermost Command
- if @teams.is_a?(String) || @teams.empty? - if @teams.empty?
= render 'no_teams' = render 'no_teams'
- else - else
= render 'team_selection' = render 'team_selection'
...@@ -27,12 +27,12 @@ module Mattermost ...@@ -27,12 +27,12 @@ module Mattermost
end end
def json_response(response) def json_response(response)
json_response = JSON.parse(response.body)
unless response.success? unless response.success?
raise Mattermost::ClientError.new(json_response['message'] || 'Undefined error') raise Mattermost::ClientError.new(json_response['message'] || 'Undefined error')
end end
json_response = JSON.parse(response.body)
json_response json_response
rescue JSON::JSONError rescue JSON::JSONError
raise Mattermost::ClientError.new('Cannot parse response') raise Mattermost::ClientError.new('Cannot parse response')
......
...@@ -113,7 +113,7 @@ describe MattermostSlashCommandsService, :models do ...@@ -113,7 +113,7 @@ describe MattermostSlashCommandsService, :models do
end end
it 'shows error messages' do it 'shows error messages' do
expect(subject).to eq([]) expect(subject).to eq([[], "Failed to get team list."])
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment