Sha256: 112edb94c2276784816b24fe1dd1209f0df465c4132ef74f1e8fa80fb11c09a7

Contents?: true

Size: 991 Bytes

Versions: 1

Compression:

Stored size: 991 Bytes

Contents

module Elastic
  module AppSearch
    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.size == 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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
elastic-app-search-7.2.0 lib/elastic/app-search/exceptions.rb