Sha256: dcea19941ed5408fd0dde139f4ecf6792d27967a480c60a746a321bdd97e457d

Contents?: true

Size: 690 Bytes

Versions: 17

Compression:

Stored size: 690 Bytes

Contents

require 'grape/exceptions/base'

module Grape
  module Exceptions
    class Validation < Grape::Exceptions::Base
      attr_accessor :params
      attr_accessor :message_key

      def initialize(params:, message: nil, **args)
        @params = params
        if message
          @message_key = message if message.is_a?(Symbol)
          args[:message] = translate_message(message)
        end
        super(args)
      end

      # remove all the unnecessary stuff from Grape::Exceptions::Base like status
      # and headers when converting a validation error to json or string
      def as_json(*_args)
        to_s
      end

      def to_s
        message
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.2.5/lib/grape/exceptions/validation.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/grape-1.2.5/lib/grape/exceptions/validation.rb
grape-1.2.5 lib/grape/exceptions/validation.rb
grape-1.2.4 lib/grape/exceptions/validation.rb
grape-1.2.3 lib/grape/exceptions/validation.rb
grape-1.2.2 lib/grape/exceptions/validation.rb
grape-1.2.1 lib/grape/exceptions/validation.rb
grape-1.2.0 lib/grape/exceptions/validation.rb
grape-1.1.0 lib/grape/exceptions/validation.rb
grape-1.0.3 lib/grape/exceptions/validation.rb
grape-1.0.2 lib/grape/exceptions/validation.rb
grape-1.0.1 lib/grape/exceptions/validation.rb
grape-1.0.0 lib/grape/exceptions/validation.rb
grape-0.19.2 lib/grape/exceptions/validation.rb
grape-0.19.1 lib/grape/exceptions/validation.rb
grape-0.19.0 lib/grape/exceptions/validation.rb
grape-0.18.0 lib/grape/exceptions/validation.rb