Exception: QRPC::Client::Exception

Inherits:
Exception
  • Object
show all
Defined in:
lib/qrpc/client/exception.rb

Overview

Queue RPC client exception.

Since:

  • 0.2.0

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Exception

Constructor. Initializes from protocol exception data object.

Parameters:

Since:

  • 0.2.0



66
67
68
69
70
71
72
73
# File 'lib/qrpc/client/exception.rb', line 66

def initialize(data)
    message = data.name.dup << ": " << data.message
    backtrace = data.backtrace.map { |i| Base64.decode64(i) }
    backtrace.reject! { |i| i.empty? }
    
    super(message)
    self.set_backtrace(backtrace)
end

Class Method Details

.get(proto) ⇒ Exception, QRPC::Client::Exception

Gets one from protocol exception object. Returns marshalled original or reconstructed version.

Parameters:

  • proto (JsonRpcObjects::Generic::Error)

    JSON-RPC error object

Returns:

Since:

  • 0.2.0



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/qrpc/client/exception.rb', line 37

def self.get(proto)

    # Converts protocol exception to exception data object
    proto = QRPC::Protocol::ExceptionData::new(proto.data)

    # Tries to unmarshall
    if proto.dump.format == :ruby
        begin
            exception = Marshal.load(Base64.decode64(proto.dump.raw))
        rescue
            # pass
        end
    end
    
    # If unsuccessfull, creates from data
    if exception.nil?
        exception = self::new(proto)
    end

    return exception
end