Exception: Rocksky::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/rocksky/error.rb

Direct Known Subclasses

HTTPError, TransportError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, status: nil, body: nil, nsid: nil) ⇒ Error

Returns a new instance of Error.



5
6
7
8
9
10
# File 'lib/rocksky/error.rb', line 5

def initialize(message, status: nil, body: nil, nsid: nil)
  super(message)
  @status = status
  @body = body
  @nsid = nsid
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/rocksky/error.rb', line 3

def body
  @body
end

#nsidObject (readonly)

Returns the value of attribute nsid.



3
4
5
# File 'lib/rocksky/error.rb', line 3

def nsid
  @nsid
end

#statusObject (readonly)

Returns the value of attribute status.



3
4
5
# File 'lib/rocksky/error.rb', line 3

def status
  @status
end

Class Method Details

.from_response(status, body, nsid: nil) ⇒ Object



12
13
14
15
16
# File 'lib/rocksky/error.rb', line 12

def self.from_response(status, body, nsid: nil)
  message = extract_message(body) || "request failed"
  klass = klass_for(status)
  klass.new(message, status: status, body: body, nsid: nsid)
end

.from_transport(cause, nsid: nil) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/rocksky/error.rb', line 18

def self.from_transport(cause, nsid: nil)
  TransportError.new(
    "transport error: #{cause.class}: #{cause.message}",
    body: nil,
    nsid: nsid
  )
end