Sha256: aea71214b238006eac061bd63a1e0e93e5196ea41c7880d2ead9f51dffbfe3c0

Contents?: true

Size: 831 Bytes

Versions: 5

Compression:

Stored size: 831 Bytes

Contents

module SwiftypeAppSearch
  class ClientException < StandardError
    attr_reader :errors

    def initialize(response)
      @errors = response['errors'] || [ response ]
      message = (errors.count == 1) ? "Error: #{errors.first}" : "Errors: #{errors.inspect}"
      super(message)
    end
  end

  class NonExistentRecord < ClientException; end
  class InvalidCredentials < ClientException; end
  class BadRequest < ClientException; end
  class Forbidden < ClientException; end
  class InvalidDocument < ClientException; end
  class RequestEntityTooLarge < ClientException; end

  class UnexpectedHTTPException < ClientException
    def initialize(response, response_json)
      errors = (response_json['errors'] || [response.message]).map { |e| "(#{response.code}) #{e}" }
      super({ 'errors' => errors })
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
swiftype-app-search-0.4.0 lib/swiftype-app-search/exceptions.rb
swiftype-app-search-0.3.0 lib/swiftype-app-search/exceptions.rb
swiftype-app-search-0.2.0 lib/swiftype-app-search/exceptions.rb
swiftype-app-search-0.1.4 lib/swiftype-app-search/exceptions.rb
swiftype-app-search-0.1.3 lib/swiftype-app-search/exceptions.rb