Sha256: cd29525440fb9e206baf573047a982aa7ae04cd931b243fc88e93a63bf403dab

Contents?: true

Size: 643 Bytes

Versions: 3

Compression:

Stored size: 643 Bytes

Contents

require 'grape/exceptions/base'

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

      def initialize(args = {})
        fail 'Params are missing:' unless args.key? :params
        @params = args[:params]
        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

3 entries across 3 versions & 1 rubygems

Version Path
grape-0.11.0 lib/grape/exceptions/validation.rb
grape-0.10.1 lib/grape/exceptions/validation.rb
grape-0.10.0 lib/grape/exceptions/validation.rb