Module: RPC::Encoders::Json::Errors

Included in:
Client, Server
Defined in:
lib/rpc/lib/rpc/encoders/json.rb

Overview

Instance Method Summary collapse

Instance Method Details

#error(message, code, object) ⇒ Object



30
31
32
33
34
# File 'lib/rpc/lib/rpc/encoders/json.rb', line 30

def error(message, code, object)
  error = {name: "JSONRPCError", code: code, message: message, error: object}
  RPC.log "ERROR #{message} (#{code}) #{error[:error].inspect}"
  error
end

#exception(exception, code = 000, message = "#{exception.class}: #{exception.message}") ⇒ Object

Note:

The exceptions are “eaten”, because no client should be able to shut the server down.



21
22
23
24
25
26
27
28
# File 'lib/rpc/lib/rpc/encoders/json.rb', line 21

def exception(exception, code = 000, message = "#{exception.class}: #{exception.message}")
  unless RPC.development?
    object = {class: exception.class.to_s, message: exception.message, backtrace: exception.backtrace}
    self.error(message, code, object)
  else
    raise exception
  end
end