Class: PipeRpc::Hub::Message::ErrorResponse

Inherits:
ErrorResponse show all
Defined in:
lib/pipe_rpc/hub_message_error_response.rb

Instance Attribute Summary

Attributes inherited from ErrorResponse

#code, #data, #id, #message

Instance Method Summary collapse

Methods inherited from ErrorResponse

#to_h

Constructor Details

#initialize(hub, body) ⇒ ErrorResponse

Returns a new instance of ErrorResponse.



5
6
7
8
# File 'lib/pipe_rpc/hub_message_error_response.rb', line 5

def initialize(hub, body)
  @hub = hub
  super body
end

Instance Method Details

#handleObject



18
19
20
# File 'lib/pipe_rpc/hub_message_error_response.rb', line 18

def handle
  raise to_error
end

#to_errorObject



10
11
12
13
14
15
16
# File 'lib/pipe_rpc/hub_message_error_response.rb', line 10

def to_error
  case @code
  when -32700 then MessageParseError.new(@data.fetch(:message))
  when -32600 then InvalidMessageError.new(@data.fetch(:message))
  else UnknownError.new(@data[:message])
  end
end