Module: AnyCable::Handler::CaptureExceptions

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

Overview

Handle app-level errors.

NOTE: this functionality couldn’t be implemeted as middleware, ‘cause interceptors do not support aborting the call and returning a data

Constant Summary collapse

RESPONSE_CLASS =
{
  command: AnyCable::CommandResponse,
  connect: AnyCable::ConnectionResponse,
  disconnect: AnyCable::DisconnectResponse
}.freeze

Instance Method Summary collapse

Instance Method Details

#capture_exceptions(method_name) ⇒ Object



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

def capture_exceptions(method_name)
  yield
rescue StandardError => exp
  AnyCable::ExceptionsHandling.notify(exp)

  RESPONSE_CLASS.fetch(method_name).new(
    status: AnyCable::Status::ERROR,
    error_msg: exp.message
  )
end