Sha256: 86255c8fcaefba8fc8fdb16fac550168ba6add3dd7728324e9fd6baa16fe893b
Contents?: true
Size: 1.18 KB
Versions: 10
Compression:
Stored size: 1.18 KB
Contents
module Elastic module AppSearch class ClientException < StandardError attr_reader :errors def extract_messages(response) errors_value = response['errors'] return errors_value if errors_value && errors_value.is_a?(Array) return [errors_value] if errors_value && !errors_value.is_a?(Array) [response] end def initialize(response) @errors = response.is_a?(Array) ? response.flat_map { |r| extract_messages(r) } : extract_messages(response) 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
10 entries across 10 versions & 1 rubygems