@@ -15,7 +15,7 @@ class Client < ::RedisClient
15
15
RedisClient ::WrongTypeError => Redis ::WrongTypeError ,
16
16
RedisClient ::ReadOnlyError => Redis ::ReadOnlyError ,
17
17
RedisClient ::ProtocolError => Redis ::ProtocolError ,
18
- } . freeze
18
+ }
19
19
20
20
class << self
21
21
def config ( **kwargs )
@@ -78,7 +78,7 @@ def password
78
78
def call_v ( command , &block )
79
79
super ( command , &block )
80
80
rescue ::RedisClient ::Error => error
81
- raise ERROR_MAPPING . fetch ( error . class ) , error . message , error . backtrace
81
+ translate_error! ( error )
82
82
end
83
83
84
84
def blocking_call_v ( timeout , command , &block )
@@ -91,19 +91,19 @@ def blocking_call_v(timeout, command, &block)
91
91
92
92
super ( timeout , command , &block )
93
93
rescue ::RedisClient ::Error => error
94
- raise ERROR_MAPPING . fetch ( error . class ) , error . message , error . backtrace
94
+ translate_error! ( error )
95
95
end
96
96
97
97
def pipelined
98
98
super
99
99
rescue ::RedisClient ::Error => error
100
- raise ERROR_MAPPING . fetch ( error . class ) , error . message , error . backtrace
100
+ translate_error! ( error )
101
101
end
102
102
103
103
def multi
104
104
super
105
105
rescue ::RedisClient ::Error => error
106
- raise ERROR_MAPPING . fetch ( error . class ) , error . message , error . backtrace
106
+ translate_error! ( error )
107
107
end
108
108
109
109
def disable_reconnection ( &block )
@@ -121,6 +121,21 @@ def close
121
121
122
122
private
123
123
124
+ def translate_error! ( error )
125
+ redis_error = translate_error_class ( error . class )
126
+ raise redis_error , error . message , error . backtrace
127
+ end
128
+
129
+ def translate_error_class ( error_class )
130
+ ERROR_MAPPING . fetch ( error_class )
131
+ rescue IndexError
132
+ if ( client_error = error_class . ancestors . find { |a | ERROR_MAPPING [ a ] } )
133
+ ERROR_MAPPING [ error_class ] = ERROR_MAPPING [ client_error ]
134
+ else
135
+ raise
136
+ end
137
+ end
138
+
124
139
def ensure_connected ( retryable : true )
125
140
unless @inherit_socket || ( @pid ||= Process . pid ) == Process . pid
126
141
raise InheritedError ,
0 commit comments