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
end
def teams
@teams ||= begin
teams, error_message = @service.list_teams(current_user)
error_message ? error_message : teams
end
@teams, @teams_error_message = @service.list_teams(current_user)
end
def service
......
......@@ -28,10 +28,10 @@ class MattermostSlashCommandsService < ChatSlashCommandsService
[false, e.message]
end
def list_teams(user)
Mattermost::Team.new(user).all
rescue Mattermost::Error
[]
def list_teams(current_user)
[Mattermost::Team.new(current_user).all, nil]
rescue Mattermost::Error => e
[[], e.message]
end
private
......
= content_for :flash_message do
.alert.alert-danger= @teams if @teams.is_a?(String)
- if @teams_error_message
= content_for :flash_message do
.alert.alert-danger= @teams_error_message
%p
You aren’t a member of any team on the Mattermost instance at
......
......@@ -2,7 +2,7 @@
.inline.pull-right
= custom_icon('mattermost_logo', size: 48)
%h3 Install Mattermost Command
- if @teams.is_a?(String) || @teams.empty?
- if @teams.empty?
= render 'no_teams'
- else
= render 'team_selection'
......@@ -27,12 +27,12 @@ module Mattermost
end
def json_response(response)
json_response = JSON.parse(response.body)
unless response.success?
raise Mattermost::ClientError.new(json_response['message'] || 'Undefined error')
end
json_response = JSON.parse(response.body)
json_response
rescue JSON::JSONError
raise Mattermost::ClientError.new('Cannot parse response')
......
......@@ -113,7 +113,7 @@ describe MattermostSlashCommandsService, :models do
end
it 'shows error messages' do
expect(subject).to eq([])
expect(subject).to eq([[], "Failed to get team list."])
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