Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/meilisearch/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def initialize(message)
class TimeoutError < StandardError
attr_reader :message

def initialize
@message = 'The update was not processed in the expected time'
def initialize(message = nil)
@message = "The request was not processed in the expected time. #{message}"
super(@message)
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/meilisearch/http_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ def send_request(http_method, relative_path, config: {})

begin
response = http_method.call(@base_url + relative_path, config)
rescue Errno::ECONNREFUSED => e
rescue Errno::ECONNREFUSED, Errno::EPIPE => e
raise CommunicationError, e.message
rescue Net::ReadTimeout, Net::OpenTimeout => e
raise TimeoutError, e.message
end

validate(response)
Expand Down
25 changes: 25 additions & 0 deletions spec/meilisearch/client/errors_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

RSpec.describe 'MeiliSearch::Client - Errors' do
context 'when request takes to long to answer' do
it 'raises MeiliSearch::TimeoutError' do
timed_client = MeiliSearch::Client.new(URL, MASTER_KEY, { timeout: 0.000001 })

expect do
timed_client.version
end.to raise_error(MeiliSearch::TimeoutError)
end
end

context 'when body is too large' do
let(:index) { client.index('movies') }

it 'raises MeiliSearch::CommunicationError' do
allow(index.class).to receive(:post).and_raise(Errno::EPIPE)

expect do
index.add_documents([{ id: 1, text: 'my_text' }])
end.to raise_error(MeiliSearch::CommunicationError)
end
end
end
2 changes: 1 addition & 1 deletion spec/meilisearch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

expect do
new_client.indexes
end.to raise_error(Timeout::Error)
end.to raise_error(MeiliSearch::TimeoutError)
end

it 'has a pre-defined header with current version' do
Expand Down