Sha256: 3f9ae2423077e61b740a06d28e12a9e71c14a8569524427549a23bd9de1ba6a1

Contents?: true

Size: 929 Bytes

Versions: 6

Compression:

Stored size: 929 Bytes

Contents

module SwiftypeAppSearch
  class ClientException < StandardError
    attr_reader :errors

    def initialize(response)
      @errors = if response.is_a?(Array)
        response.flat_map { |r| r['errors'] }
      else
        response['errors'] || [response]
      end
      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

6 entries across 6 versions & 1 rubygems

Version Path
swiftype-app-search-0.6.1 lib/swiftype-app-search/exceptions.rb
swiftype-app-search-0.6.0 lib/swiftype-app-search/exceptions.rb
swiftype-app-search-0.5.0 lib/swiftype-app-search/exceptions.rb
swiftype-app-search-0.4.4 lib/swiftype-app-search/exceptions.rb
swiftype-app-search-0.4.2 lib/swiftype-app-search/exceptions.rb
swiftype-app-search-0.4.1 lib/swiftype-app-search/exceptions.rb