Module: ErrorResponse

Defined in:
lib/error_response.rb,
lib/error_response/helper.rb,
lib/error_response/configuration.rb,
lib/error_response/request_error.rb

Defined Under Namespace

Modules: Helper Classes: Configuration, RequestError

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject



15
16
17
# File 'lib/error_response.rb', line 15

def configuration
  @configuration ||= Configuration.new
end

Class Method Details

.allObject



23
24
25
# File 'lib/error_response.rb', line 23

def all
  yaml_hash
end

.configure {|configuration| ... } ⇒ Object

Yields:



19
20
21
# File 'lib/error_response.rb', line 19

def configure
  yield(configuration)
end

.to_api(key, message = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/error_response.rb', line 33

def to_api(key, message = nil)
  json = deep_dup(yaml_hash)
  json = json[key.to_s] || { "error_code" => 500_000, "error_message" => key.to_s }
  json["error_key"] = key.to_s
  json["error_message"] += ": #{message}" unless message.nil?
  {
    status: parse_status(json["error_code"]),
    json: json
  }
end

.to_hash(key) ⇒ Object



27
28
29
30
31
# File 'lib/error_response.rb', line 27

def to_hash(key)
  return {} unless yaml_hash.key?(key.to_s)

  yaml_hash[key.to_s].merge({ "error_key" => key.to_s })
end