class THTP::Client::Middleware::SchemaValidation

Raise Thrift validation issues as their own detectable error type, rather than just ProtocolException.

Public Class Methods

new(app) click to toggle source
# File lib/thtp/client/middleware.rb, line 10
def initialize(app)
  require 'thrift/validator' # if you don't have it, you'll need it
  @app = app
  @validator = Thrift::Validator.new
end

Public Instance Methods

call(rpc, *rpc_args, **rpc_opts) click to toggle source

Raises a ValidationError if any part of the request or response did not match the schema

# File lib/thtp/client/middleware.rb, line 18
def call(rpc, *rpc_args, **rpc_opts)
  @validator.validate(rpc_args)
  @app.call(rpc, *rpc_args, **rpc_opts).tap { |resp| @validator.validate(resp) }
rescue Thrift::ProtocolException => e
  raise ClientValidationError, e.message
end