Sha256: cd897eb6fb5a522f092e4872c6c5fc06bce1e984175e68df90bd446d1dad55a7

Contents?: true

Size: 629 Bytes

Versions: 5

Compression:

Stored size: 629 Bytes

Contents

# frozen_string_literal: true

module Grape
  module Exceptions
    class Validation < Grape::Exceptions::Base
      attr_accessor :params, :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
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
grape-2.2.0 lib/grape/exceptions/validation.rb
grape-2.1.3 lib/grape/exceptions/validation.rb
grape-2.1.2 lib/grape/exceptions/validation.rb
grape-2.1.1 lib/grape/exceptions/validation.rb
grape-2.1.0 lib/grape/exceptions/validation.rb