Exception: Pobo::ApiError

Inherits:
Error
  • Object
show all
Defined in:
lib/pobo/errors.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, http_code: nil, response_body: nil) ⇒ ApiError

Returns a new instance of ApiError.



9
10
11
12
13
# File 'lib/pobo/errors.rb', line 9

def initialize(message, http_code: nil, response_body: nil)
  @http_code = http_code
  @response_body = response_body
  super(message)
end

Instance Attribute Details

#http_code ⇒ Object (readonly)

Returns the value of attribute http_code.



7
8
9
# File 'lib/pobo/errors.rb', line 7

def http_code
  @http_code
end

#response_body ⇒ Object (readonly)

Returns the value of attribute response_body.



7
8
9
# File 'lib/pobo/errors.rb', line 7

def response_body
  @response_body
end

Class Method Details

.from_response(http_code, body) ⇒ Object



19
20
21
22
# File 'lib/pobo/errors.rb', line 19

def self.from_response(http_code, body)
  message = body.is_a?(Hash) ? (body["error"] || body["message"] || "API error") : "API error"
  new(message, http_code: http_code, response_body: body)
end

.unauthorized ⇒ Object



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

def self.unauthorized
  new("Authorization token required", http_code: 401)
end