Class: OpenC3::JsonRpcError

Inherits:
JsonRpc show all
Defined in:
lib/openc3/io/json_rpc.rb

Overview

Represents a JSON Remote Procedure Call Error

Defined Under Namespace

Classes: ErrorCode

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from JsonRpc

#<=>, #as_json, #to_json

Constructor Details

#initialize(code, message, data = nil) ⇒ JsonRpcError



405
406
407
408
409
410
# File 'lib/openc3/io/json_rpc.rb', line 405

def initialize(code, message, data = nil)
  super()
  @hash['code'] = code
  @hash['message'] = message
  @hash['data'] = data
end

Class Method Details

.from_hash(hash) ⇒ JsonRpcError

Creates a JsonRpcError object from a Hash



432
433
434
435
436
437
438
# File 'lib/openc3/io/json_rpc.rb', line 432

def self.from_hash(hash)
  if hash['code'] and (hash['code'].to_i == hash['code']) and hash['message']
    self.new(hash['code'], hash['message'], hash['data'])
  else
    raise "Invalid JSON-RPC 2.0 Error\n#{hash.inspect}\n"
  end
end

Instance Method Details

#codeInteger



413
414
415
# File 'lib/openc3/io/json_rpc.rb', line 413

def code
  @hash['code']
end

#dataHash



423
424
425
# File 'lib/openc3/io/json_rpc.rb', line 423

def data
  @hash['data']
end

#messageString



418
419
420
# File 'lib/openc3/io/json_rpc.rb', line 418

def message
  @hash['message']
end