Exception: Notifications::Client::RequestError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/notifications/client/request_error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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
  @message = message_from(response.body)
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



4
5
6
# File 'lib/notifications/client/request_error.rb', line 4

def code
  @code
end

#messageObject (readonly)

Returns the value of attribute message.



4
5
6
# File 'lib/notifications/client/request_error.rb', line 4

def message
  @message
end

Instance Method Details

#message_from(body) ⇒ Object



15
16
17
18
19
# File 'lib/notifications/client/request_error.rb', line 15

def message_from(body)
  JSON.parse(body).fetch("message")
rescue JSON::ParserError
  body
end

#to_sObject



11
12
13
# File 'lib/notifications/client/request_error.rb', line 11

def to_s
  "#{code} #{message}"
end