Exception: Ridley::Errors::HTTPError

Inherits:
RidleyError
  • Object
show all
Defined in:
lib/ridley/errors.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ HTTPError

Returns a new instance of HTTPError.



113
114
115
116
117
118
119
120
121
122
123
# File 'lib/ridley/errors.rb', line 113

def initialize(env)
  @env = env
  @errors = env[:body].is_a?(Hash) ? Array(env[:body][:error]) : []

  if errors.empty?
    @message = env[:body] || "no content body"
  else
    @message = "errors: "
    @message << errors.collect { |e| "'#{e}'" }.join(', ')
  end
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



107
108
109
# File 'lib/ridley/errors.rb', line 107

def env
  @env
end

#errorsObject (readonly)

Returns the value of attribute errors.



108
109
110
# File 'lib/ridley/errors.rb', line 108

def errors
  @errors
end

#messageObject (readonly) Also known as: to_s

Returns the value of attribute message.



110
111
112
# File 'lib/ridley/errors.rb', line 110

def message
  @message
end

Class Method Details

.error_mapObject



102
103
104
# File 'lib/ridley/errors.rb', line 102

def error_map
  @@error_map ||= Hash.new
end

.fabricate(env) ⇒ Object



87
88
89
90
# File 'lib/ridley/errors.rb', line 87

def fabricate(env)
  klass = lookup_error(env[:status].to_i)
  klass.new(env)
end

.lookup_error(status) ⇒ Object



96
97
98
99
100
# File 'lib/ridley/errors.rb', line 96

def lookup_error(status)
  error_map.fetch(status.to_i)
rescue KeyError
  HTTPUnknownStatus
end

.register_error(status) ⇒ Object



92
93
94
# File 'lib/ridley/errors.rb', line 92

def register_error(status)
  error_map[status.to_i] = self
end