class Protobuf::Rpc::Middleware::ExceptionHandler
def _call(env)
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 = wrap_and_encode_with_server(env.response, env) env end
def call(env)
def call(env) dup._call(env) end
def initialize(app)
def initialize(app) @app = app end
def wrap_and_encode_with_server(response, env)
We should add it here since exception handler is always at the bottom of the middleware
If the response is a PbError, it won't have the server merged into the response proto.
def wrap_and_encode_with_server(response, env) if response.is_a?(PbError) response.encode(:server => env.server) else response.encode end end
def wrap_exception(exception)
Wrap exceptions in a generic Protobuf errors unless they already are
def wrap_exception(exception) exception = RpcFailed.new(exception.message) unless exception.is_a?(PbError) exception end