Sha256: ba2e0ab5c1533f70203b31829772bedde5672520a079cc4dfdd4551c4ec537ed

Contents?: true

Size: 723 Bytes

Versions: 8

Compression:

Stored size: 723 Bytes

Contents

# frozen_string_literal: true

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

8 entries across 8 versions & 2 rubygems

Version Path
grape-1.5.1 lib/grape/exceptions/validation.rb
grape-1.5.0 lib/grape/exceptions/validation.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.4.0/lib/grape/exceptions/validation.rb
grape-1.4.0 lib/grape/exceptions/validation.rb
grape-1.3.3 lib/grape/exceptions/validation.rb
grape-1.3.2 lib/grape/exceptions/validation.rb
grape-1.3.1 lib/grape/exceptions/validation.rb
grape-1.3.0 lib/grape/exceptions/validation.rb