Exception: F00px::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/f00px/error.rb,
lib/f00px/error/forbidden.rb,
lib/f00px/error/unauthorized.rb

Direct Known Subclasses

Forbidden, Unauthorized

Defined Under Namespace

Classes: Forbidden, Unauthorized

Class Method Summary collapse

Class Method Details

.from_response(response) ⇒ Object



11
12
13
14
# File 'lib/f00px/error.rb', line 11

def from_response(response)
  klass = @errors[response.status] || self
  klass.new(parse_error(response.body))
end

.parse_error(body) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/f00px/error.rb', line 16

def parse_error(body)
  return body if body.is_a? String
  if body.nil?
    ''
  elsif body[:error]
    body[:error]
  elsif body[:errors]
    first = Array(body[:errors]).first
    if first.is_a?(Hash)
      first[:message].chomp
    else
      first.chomp
    end
  end
end

.register_error(error) ⇒ Object



6
7
8
9
# File 'lib/f00px/error.rb', line 6

def register_error(error)
  @errors ||= {}
  @errors[error::STATUS_CODE] = error
end