Sha256: f777d666a262143ff41fda9ecf89944faefdd1d77facc8822d65e8f0042e0144

Contents?: true

Size: 638 Bytes

Versions: 2

Compression:

Stored size: 638 Bytes

Contents

require 'grape/exceptions/base'

module Grape
  module Exceptions
    class Validation < Grape::Exceptions::Base
      attr_accessor :param

      def initialize(args = {})
        raise "Param is missing:" unless args.key? :param
        @param = args[:param]
        args[:message] = translate_message(args[:message_key]) if args.key? :message_key
        super
      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

2 entries across 2 versions & 2 rubygems

Version Path
grape-security-0.8.0 lib/grape/exceptions/validation.rb
grape-0.8.0 lib/grape/exceptions/validation.rb