Skip to content

Commit

Permalink
raise a specific error when a required server tag is not available (#…
Browse files Browse the repository at this point in the history
…1091)

Co-authored-by: Ahmad Farhat <ahmad.af.farhat@gmail.com>
  • Loading branch information
Ithanil and farhatahmad authored Jun 28, 2024
1 parent d36c85d commit 5a25fcb
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions app/controllers/concerns/bbb_errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,10 @@ def initialize
super('serverUnavailable', 'The server for this meeting is disabled/offline.')
end
end

class ServerTagUnavailableError < BBBError
def initialize(tag)
super('serverTagUnavailable', "There is no available server with the required tag=#{tag}.")
end
end
end
2 changes: 1 addition & 1 deletion app/models/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def self.find_available(tag_arg = nil)
ids_loads = redis.zrange('server_load', 0, -1, with_scores: true)
raise RecordNotFound.new("Could not find any available servers.", name, nil) if ids_loads.blank?
if !tag.nil? && ids_loads.none? { |myid, _| redis.hget(key(myid), 'tag') == tag }
raise RecordNotFound.new("Could not find any available servers with tag=#{tag}.", name, nil) if tag_required
raise BBBErrors::ServerTagUnavailableError, tag if tag_required
tag = nil # fall back to servers without tag
end
ids_loads = ids_loads.select { |myid, _| redis.hget(key(myid), 'tag') == tag }
Expand Down
2 changes: 1 addition & 1 deletion spec/models/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@
it 'raises error with specific message' do
expect {
described_class.find_available('test-tag!')
}.to raise_error(ApplicationRedisRecord::RecordNotFound, "Could not find any available servers with tag=test-tag.")
}.to raise_error(BBBErrors::ServerTagUnavailableError)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/bigbluebutton_api_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@
get bigbluebutton_api_create_url, params: { meetingID: "test-meeting-1", "meta_server-tag" => "test-tag!" }

response_xml = Nokogiri.XML(response.body)
expected_error = BBBErrors::InternalError.new("Could not find any available servers with tag=test-tag.")
expected_error = BBBErrors::ServerTagUnavailableError.new("test-tag")
expect(response_xml.at_xpath("/response/returncode").text).to(eq("FAILED"))
expect(response_xml.at_xpath("/response/messageKey").text).to(eq(expected_error.message_key))
expect(response_xml.at_xpath("/response/message").text).to(eq(expected_error.message))
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/bigbluebutton_api_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ class BigBlueButtonApiControllerTest < ActionDispatch::IntegrationTest

response_xml = Nokogiri::XML(@response.body)

expected_error = InternalError.new('Could not find any available servers with tag=test-tag.')
expected_error = ServerTagUnavailableError.new('test-tag')

assert_equal 'FAILED', response_xml.at_xpath('/response/returncode').text
assert_equal expected_error.message_key, response_xml.at_xpath('/response/messageKey').text
Expand Down
2 changes: 1 addition & 1 deletion test/models/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ class ServerTest < ActiveSupport::TestCase
redis.zadd('server_load', 1, 'test-2')
end

assert_raises(ApplicationRedisRecord::RecordNotFound, "Could not find any available servers with tag=test-tag.") do
assert_raises(BBBErrors::ServerTagUnavailableError) do
Server.find_available('test-tag!')
end
end
Expand Down

0 comments on commit 5a25fcb

Please sign in to comment.