grape icon indicating copy to clipboard operation
grape copied to clipboard

Error in AsValidator when using nested parameters

Open bforma opened this issue 4 years ago • 1 comments

Possible fix is to rescue all errors and re-raise as a Grape::Exceptions::Validation.

module Grape
  module Validations
    class AsValidator < Base
      def initialize(attrs, options, required, scope, opts = {})
        @renamed_options = options
        super
      end

      def validate_param!(attr_name, params)
        params[@renamed_options] = params[attr_name]
      rescue StandardError => _e
        raise Grape::Exceptions::Validation.new(
          params: [@scope.full_name(attr_name)],
          message: message(:invalid_format),
        )
      end
    end
  end
end

bforma avatar Apr 28 '20 11:04 bforma

Please PR a spec + this?

dblock avatar Apr 28 '20 19:04 dblock