Exception: Notifications::Client::RequestError
- Inherits:
-
StandardError
- Object
- StandardError
- Notifications::Client::RequestError
- Defined in:
- lib/notifications/client/request_error.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
Instance Method Summary collapse
-
#initialize(response) ⇒ RequestError
constructor
A new instance of RequestError.
- #message ⇒ Object
- #parse_body(body) ⇒ Object
Constructor Details
#initialize(response) ⇒ RequestError
Returns a new instance of RequestError.
6 7 8 9 |
# File 'lib/notifications/client/request_error.rb', line 6 def initialize(response) @code = response.code @body = parse_body(response.body) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
4 5 6 |
# File 'lib/notifications/client/request_error.rb', line 4 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
4 5 6 |
# File 'lib/notifications/client/request_error.rb', line 4 def code @code end |
Instance Method Details
#message ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/notifications/client/request_error.rb', line 17 def return body if body.is_a?(String) = body.fetch('errors') .map { |e| "#{e.fetch('error')}: #{e.fetch('message')}" } .join(", ") end |
#parse_body(body) ⇒ Object
11 12 13 14 15 |
# File 'lib/notifications/client/request_error.rb', line 11 def parse_body(body) JSON.parse(body) rescue JSON::ParserError body end |