module Aws::Errors::DynamicErrors
def self.extended(submodule)
def self.extended(submodule) submodule.instance_variable_set('@const_set_mutex', Mutex.new) submodule.const_set(:ServiceError, Class.new(ServiceError)) end
def const_missing(constant)
def const_missing(constant) set_error_constant(constant) end
def error_class(error_code)
- Api: - private
def error_class(error_code) constant = error_class_constant(error_code) if error_const_set?(constant) # modeled error class exist # set code attribute err_class = const_get(constant) err_class.code = constant.to_s err_class else set_error_constant(constant) end end
def error_class_constant(error_code)
-
(Symbol)
- Returns a symbolized constant name for the given
Parameters:
-
error_code
(String
) --
def error_class_constant(error_code) constant = error_code.to_s constant = constant.gsub(/https?:.*$/, '') constant = constant.gsub(/[^a-zA-Z0-9]/, '') constant = 'Error' + constant unless constant.match(/^[a-z]/i) constant = constant[0].upcase + constant[1..-1] constant.to_sym end
def error_const_set?(constant)
def error_const_set?(constant) # Purposefully not using #const_defined? as that method returns true # for constants not defined directly in the current module. constants.include?(constant.to_sym) end
def set_error_constant(constant)
def set_error_constant(constant) @const_set_mutex.synchronize do # Ensure the const was not defined while blocked by the mutex if error_const_set?(constant) const_get(constant) else error_class = Class.new(const_get(:ServiceError)) error_class.code = constant.to_s const_set(constant, error_class) end end end