Sha256: 04bdd001bba67221048ab3832c8e69c634016b6b82b60deaecf0d65dc6df8425

Contents?: true

Size: 669 Bytes

Versions: 8

Compression:

Stored size: 669 Bytes

Contents

module Grape
  module ErrorFormatter
    module Json
      extend Base

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

          if (options[:rescue_options] || {})[:backtrace] && backtrace && !backtrace.empty?
            result = result.merge(backtrace: backtrace)
          end
          MultiJson.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

8 entries across 8 versions & 1 rubygems

Version Path
grape-0.19.2 lib/grape/error_formatter/json.rb
grape-0.19.1 lib/grape/error_formatter/json.rb
grape-0.19.0 lib/grape/error_formatter/json.rb
grape-0.18.0 lib/grape/error_formatter/json.rb
grape-0.17.0 lib/grape/error_formatter/json.rb
grape-0.16.2 lib/grape/error_formatter/json.rb
grape-0.16.1 lib/grape/error_formatter/json.rb
grape-0.15.0 lib/grape/error_formatter/json.rb