Sha256: 53c1054ff3247db4fb648023db945d6052ef490e80c0abbfebf2a6a52e05ca8d

Contents?: true

Size: 906 Bytes

Versions: 12

Compression:

Stored size: 906 Bytes

Contents

module Grape
  module ErrorFormatter
    module Json
      extend Base

      class << self
        def call(message, backtrace, options = {}, env = nil, original_exception = nil)
          result = wrap_message(present(message, env))

          rescue_options = options[:rescue_options] || {}
          if rescue_options[:backtrace] && backtrace && !backtrace.empty?
            result = result.merge(backtrace: backtrace)
          end
          if rescue_options[:original_exception] && original_exception
            result = result.merge(original_exception: original_exception.inspect)
          end
          ::Grape::Json.dump(result)
        end

        private

        def wrap_message(message)
          if message.is_a?(Exceptions::ValidationErrors) || message.is_a?(Hash)
            message
          else
            { error: message }
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.2.5/lib/grape/error_formatter/json.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/grape-1.2.5/lib/grape/error_formatter/json.rb
grape-1.2.5 lib/grape/error_formatter/json.rb
grape-1.2.4 lib/grape/error_formatter/json.rb
grape-1.2.3 lib/grape/error_formatter/json.rb
grape-1.2.2 lib/grape/error_formatter/json.rb
grape-1.2.1 lib/grape/error_formatter/json.rb
grape-1.2.0 lib/grape/error_formatter/json.rb
grape-1.1.0 lib/grape/error_formatter/json.rb
grape-1.0.3 lib/grape/error_formatter/json.rb
grape-1.0.2 lib/grape/error_formatter/json.rb
grape-1.0.1 lib/grape/error_formatter/json.rb