lib/peddler/errors/class_generator.rb in peddler-2.4.0 vs lib/peddler/errors/class_generator.rb in peddler-2.4.1
- old
+ new
@@ -17,10 +17,15 @@
@mutex = Mutex.new
end
def generate(name)
with_mutex do
- return Errors.const_get(name) if Errors.const_defined?(name)
+ if Errors.const_defined?(name)
+ error = Errors.const_get(name)
+ return error if error.ancestors.include?(Error)
+
+ raise TypeError, "#{name} must be a Peddler::Errors::Error"
+ end
Errors.const_set(name, Class.new(Error))
end
end