Class: DripDrop::BaseHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/dripdrop/handlers/base.rb

Direct Known Subclasses

HTTPClientHandler, HTTPServerHandler, HTTPServerHandlerResponse, WebSocketHandler, WebSocketHandler::Connection, ZMQBaseHandler

Instance Method Summary (collapse)

Instance Method Details

- (Object) handle_error(exception, *extra)



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/dripdrop/handlers/base.rb', line 8

def handle_error(exception,*extra)
  if @err_cbak
    begin
      @err_cbak.call(exception,*extra)
    rescue StandardError => e
      print_exception(e)
    end
  else
    print_exception(exception)
  end
end

- (Object) on_error(&block)



4
5
6
# File 'lib/dripdrop/handlers/base.rb', line 4

def on_error(&block)
  @err_cbak = block
end


20
21
22
23
24
25
26
27
# File 'lib/dripdrop/handlers/base.rb', line 20

def print_exception(exception)
  if exception.is_a?(Exception)
    $stderr.write exception.message
    $stderr.write exception.backtrace.join("\t\n")
  else
    $stderr.write "Expected an exception, got: #{exception.inspect}"
  end
end