1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
# frozen_string_literal: true
class RedisClient
class Cluster
module ErrorIdentification
def self.client_owns_error?(err, client)
return true unless identifiable?(err)
err.from?(client)
end
def self.identifiable?(err)
err.is_a?(TaggedError)
end
module TaggedError
attr_accessor :config_instance
def from?(client)
client.config.equal?(config_instance)
end
end
module Middleware
def connect(config)
super
rescue RedisClient::Error => e
identify_error(e, config)
raise
end
def call(_command, config)
super
rescue RedisClient::Error => e
identify_error(e, config)
raise
end
def call_pipelined(_command, config)
super
rescue RedisClient::Error => e
identify_error(e, config)
raise
end
private
def identify_error(err, config)
err.singleton_class.include(TaggedError)
err.config_instance = config
end
end
end
end
end
|