Skip to content

Commit

Permalink
Merge bea47de into 01b1c89
Browse files Browse the repository at this point in the history
  • Loading branch information
ellnix authored Oct 6, 2023
2 parents 01b1c89 + bea47de commit 573fe33
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/meilisearch/error.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# frozen_string_literal: true

module MeiliSearch
class ApiError < StandardError
class Error < StandardError
end

class ApiError < Error
# :http_code # e.g. 400, 404...
# :http_message # e.g. Bad Request, Not Found...
# :http_body # The response body received from the MeiliSearch API
Expand Down Expand Up @@ -45,7 +48,7 @@ def details
end
end

class CommunicationError < StandardError
class CommunicationError < Error
attr_reader :message

def initialize(message)
Expand All @@ -54,7 +57,7 @@ def initialize(message)
end
end

class TimeoutError < StandardError
class TimeoutError < Error
attr_reader :message

def initialize(message = nil)
Expand Down
8 changes: 8 additions & 0 deletions spec/meilisearch/client/errors_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# frozen_string_literal: true

RSpec.describe 'MeiliSearch::Client - Errors' do
describe 'MeiliSearch::Error' do
it 'catches all other errors' do
expect(MeiliSearch::TimeoutError.ancestors).to include(MeiliSearch::Error)
expect(MeiliSearch::CommunicationError.ancestors).to include(MeiliSearch::Error)
expect(MeiliSearch::ApiError.ancestors).to include(MeiliSearch::Error)
end
end

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 })
Expand Down

0 comments on commit 573fe33

Please sign in to comment.