Module: Anycable::Handler::ExceptionsHandling

Included in:
RPCHandler
Defined in:
lib/anycable/handler/exceptions_handling.rb

Overview

Handle app-level errors

Instance Method Summary collapse

Instance Method Details

#commandObject



21
22
23
24
25
26
# File 'lib/anycable/handler/exceptions_handling.rb', line 21

def command(*)
  super
rescue StandardError => ex
  handle_exception(ex)
  Anycable::CommandResponse.new(status: Anycable::Status::ERROR, error_msg: ex.message)
end

#connectObject



7
8
9
10
11
12
# File 'lib/anycable/handler/exceptions_handling.rb', line 7

def connect(*)
  super
rescue StandardError => ex
  handle_exception(ex)
  Anycable::ConnectionResponse.new(status: Anycable::Status::ERROR, error_msg: ex.message)
end

#disconnectObject



14
15
16
17
18
19
# File 'lib/anycable/handler/exceptions_handling.rb', line 14

def disconnect(*)
  super
rescue StandardError => ex
  handle_exception(ex)
  Anycable::DisconnectResponse.new(status: Anycable::Status::ERROR, error_msg: ex.message)
end

#handle_exception(ex) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/anycable/handler/exceptions_handling.rb', line 28

def handle_exception(ex)
  Anycable.error_handlers.each do |handler|
    begin
      handler.call(ex)
    rescue StandardError => ex
      Anycable.logger.error "!!! ERROR HANDLER THREW AN ERROR !!!"
      Anycable.logger.error ex
      Anycable.logger.error ex.backtrace.join("\n") unless ex.backtrace.nil?
    end
  end
end