diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e199ec6e..4bc0a3c4 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2025-04-02 09:32:03 UTC using RuboCop version 1.75.1. +# on 2025-04-12 16:19:21 UTC using RuboCop version 1.75.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -9,7 +9,7 @@ # Offense count: 1 # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: - Max: 21 + Max: 24 # Offense count: 4 # Configuration parameters: CountComments, CountAsOne. @@ -19,7 +19,7 @@ Metrics/ClassLength: # Offense count: 4 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: - Max: 15 + Max: 18 # Offense count: 3 # Configuration parameters: Max, CountKeywordArgs. diff --git a/lib/meilisearch/http_request.rb b/lib/meilisearch/http_request.rb index 62811f0c..2c4a3b3d 100644 --- a/lib/meilisearch/http_request.rb +++ b/lib/meilisearch/http_request.rb @@ -118,6 +118,10 @@ def send_request(http_method, relative_path, config:) response = http_method.call(@base_url + relative_path, request_config) rescue Errno::ECONNREFUSED, Errno::EPIPE => e raise CommunicationError, e.message + rescue URI::InvalidURIError => e + raise CommunicationError, "Client URL missing scheme/protocol. Did you mean https://#{@base_url}" unless @base_url =~ %r{^\w+://} + + raise e rescue Net::OpenTimeout, Net::ReadTimeout => e attempts += 1 raise TimeoutError, e.message unless attempts <= max_retries && safe_to_retry?(config[:method_type], e) diff --git a/spec/meilisearch/client/errors_spec.rb b/spec/meilisearch/client/errors_spec.rb index fe3e31a3..c131d4e8 100644 --- a/spec/meilisearch/client/errors_spec.rb +++ b/spec/meilisearch/client/errors_spec.rb @@ -41,4 +41,13 @@ end.to raise_error(Meilisearch::InvalidDocumentId) end end + + context 'when url is missing protocol' do + it 'throws a CommunicationError with a useful message' do + expect do + c = Meilisearch::Client.new('localhost:7700') + c.health + end.to raise_error(Meilisearch::CommunicationError).with_message(/protocol/) + end + end end