Class: Gruf::Commander::RequestValidationInterceptor

Inherits:
Interceptors::ServerInterceptor
  • Object
show all
Defined in:
lib/gruf/commander/request_validation_interceptor.rb

Overview

Does request validation error handling

Instance Method Summary collapse

Instance Method Details

#callObject

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.messages[attr].fetch(idx, ''))
    end
  end
  fail!(
    options.fetch(:invalid_request_error_code, :invalid_argument),
    options.fetch(:invalid_request_app_error_code, :invalid_request),
    options.fetch(:invalid_request_message, 'Invalid request')
  )
end