Class: THTP::Client::Middleware::SchemaValidation
- Inherits:
-
Object
- Object
- THTP::Client::Middleware::SchemaValidation
- Defined in:
- lib/thtp/client/middleware.rb
Overview
Raise Thrift validation issues as their own detectable error type, rather than just ProtocolException.
Instance Method Summary collapse
-
#call(rpc, *rpc_args, **rpc_opts) ⇒ Object
Raises a ValidationError if any part of the request or response did not match the schema.
-
#initialize(app) ⇒ SchemaValidation
constructor
A new instance of SchemaValidation.
Constructor Details
#initialize(app) ⇒ SchemaValidation
Returns a new instance of SchemaValidation.
10 11 12 13 14 |
# 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 |
Instance Method Details
#call(rpc, *rpc_args, **rpc_opts) ⇒ Object
Raises a ValidationError if any part of the request or response did not match the schema
18 19 20 21 22 23 |
# 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. end |