Class: Gruf::Commander::RequestValidationInterceptor
- Inherits:
-
Interceptors::ServerInterceptor
- Object
- Interceptors::ServerInterceptor
- Gruf::Commander::RequestValidationInterceptor
- Defined in:
- lib/gruf/commander/request_validation_interceptor.rb
Overview
Does request validation error handling
Instance Method Summary collapse
-
#call ⇒ Object
Intercept the request and properly handle validation failures.
Instance Method Details
#call ⇒ Object
Intercept the request and properly handle validation failures
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/gruf/commander/request_validation_interceptor.rb', line 28 def call yield # this returns the protobuf message rescue Gruf::Commander::InvalidRequest => e e.request.errors.details.each do |attr, errs| errs.each_with_index do |err, idx| add_field_error(attr, err.values.first.to_sym, e.request.errors.[attr].fetch(idx, '')) end end fail!( .fetch(:invalid_request_error_code, :invalid_argument), .fetch(:invalid_request_app_error_code, :invalid_request), .fetch(:invalid_request_message, 'Invalid request') ) end |