Class: Protobuf::Rpc::Middleware::ExceptionHandler

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/protobuf/rpc/middleware/exception_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

initialize_logger, #log_exception, #log_signature, #logger, #sign_message

Constructor Details

#initialize(app) ⇒ ExceptionHandler

Returns a new instance of ExceptionHandler.



9
10
11
# File 'lib/protobuf/rpc/middleware/exception_handler.rb', line 9

def initialize(app)
  @app = app
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



7
8
9
# File 'lib/protobuf/rpc/middleware/exception_handler.rb', line 7

def app
  @app
end

Instance Method Details

#_call(env) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/protobuf/rpc/middleware/exception_handler.rb', line 17

def _call(env)
  app.call(env)
rescue => exception
  log_exception(exception)

  # Rescue exceptions, re-wrap them as generic Protobuf errors,
  # and encode them
  env.response = wrap_exception(exception)
  env.encoded_response = env.response.encode
  env
end

#call(env) ⇒ Object



13
14
15
# File 'lib/protobuf/rpc/middleware/exception_handler.rb', line 13

def call(env)
  dup._call(env)
end