Class: Deepstream::ErrorHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/deepstream/error_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ ErrorHandler

Returns a new instance of ErrorHandler.



9
10
11
12
# File 'lib/deepstream/error_handler.rb', line 9

def initialize(client)
  @client = client
  @error = nil
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



7
8
9
# File 'lib/deepstream/error_handler.rb', line 7

def error
  @error
end

Instance Method Details

#on_error(message) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/deepstream/error_handler.rb', line 14

def on_error(message)
  @error =
    if message.is_a?(Message)
      message.topic == TOPIC::ERROR ? message.data : Helpers.to_type(message.data.last)
    else
      message
    end
  puts "#{@error}\n" unless @client.options[:debug]
end

#on_exception(exception) ⇒ Object



24
25
26
27
# File 'lib/deepstream/error_handler.rb', line 24

def on_exception(exception)
  raise exception if @client.options[:debug]
  puts "\n#{exception.message}\n#{exception.backtrace}\n"
end