class Protobuf::Rpc::Middleware::ExceptionHandler

Attributes

app[R]

Public Class Methods

new(app) click to toggle source
# File lib/protobuf/rpc/middleware/exception_handler.rb, line 9
def initialize(app)
  @app = app
end

Public Instance Methods

_call(env) click to toggle source
# 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) click to toggle source
# File lib/protobuf/rpc/middleware/exception_handler.rb, line 13
def call(env)
  dup._call(env)
end

Private Instance Methods

wrap_exception(exception) click to toggle source

Wrap exceptions in a generic Protobuf errors unless they already are

# File lib/protobuf/rpc/middleware/exception_handler.rb, line 33
def wrap_exception(exception)
  exception = RpcFailed.new(exception.message) unless exception.is_a?(PbError)
  exception
end