Sha256: 363d86192e599e3702bcef1199e15da84d9c0b9fd877f0c8e66a3de1a7b411fd

Contents?: true

Size: 898 Bytes

Versions: 35

Compression:

Stored size: 898 Bytes

Contents

module Protobuf
  module Rpc
    module Middleware
      class ExceptionHandler
        include ::Protobuf::Logging

        attr_reader :app

        def initialize(app)
          @app = app
        end

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

        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

        private

        # 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
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 3 rubygems

Version Path
protobuf-3.10.5 lib/protobuf/rpc/middleware/exception_handler.rb
protobuf-3.10.4 lib/protobuf/rpc/middleware/exception_handler.rb
protobuf-cucumber-3.10.8 lib/protobuf/rpc/middleware/exception_handler.rb
protobuf-cucumber-3.10.7 lib/protobuf/rpc/middleware/exception_handler.rb
protobuf-cucumber-3.10.6 lib/protobuf/rpc/middleware/exception_handler.rb
protobuf-cucumber-3.10.5 lib/protobuf/rpc/middleware/exception_handler.rb
protobuf-cucumber-3.10.4 lib/protobuf/rpc/middleware/exception_handler.rb
protobuf-3.10.3 lib/protobuf/rpc/middleware/exception_handler.rb
protobuf-3.10.2 lib/protobuf/rpc/middleware/exception_handler.rb
protobuf-3.10.1 lib/protobuf/rpc/middleware/exception_handler.rb
protobuf-3.10.0 lib/protobuf/rpc/middleware/exception_handler.rb
protobuf-3.10.0.pre0 lib/protobuf/rpc/middleware/exception_handler.rb
protobuf-3.9.0 lib/protobuf/rpc/middleware/exception_handler.rb
protobuf-3.9.0.pre2 lib/protobuf/rpc/middleware/exception_handler.rb
protobuf-3.9.0.pre lib/protobuf/rpc/middleware/exception_handler.rb
protobuf-3.8.5 lib/protobuf/rpc/middleware/exception_handler.rb
protobuf-3.8.5.pre0 lib/protobuf/rpc/middleware/exception_handler.rb
protobuf-3.8.4 lib/protobuf/rpc/middleware/exception_handler.rb
protobuf-3.8.3 lib/protobuf/rpc/middleware/exception_handler.rb
protobuf-3.8.2 lib/protobuf/rpc/middleware/exception_handler.rb