Module: Grape::ErrorFormatter::Txt

Extended by:
Base
Defined in:
lib/grape/error_formatter/txt.rb

Class Method Summary collapse

Methods included from Base

present

Class Method Details

.call(message, backtrace, options = {}, env = nil, original_exception = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/grape/error_formatter/txt.rb', line 9

def call(message, backtrace, options = {}, env = nil, original_exception = nil)
  message = present(message, env)

  result = message.is_a?(Hash) ? ::Grape::Json.dump(message) : message
  Array.wrap(result).tap do |final_result|
    rescue_options = options[:rescue_options] || {}
    if rescue_options[:backtrace] && backtrace.present?
      final_result << 'backtrace:'
      final_result.concat(backtrace)
    end
    if rescue_options[:original_exception] && original_exception
      final_result << 'original exception:'
      final_result << original_exception.inspect
    end
  end.join("\r\n ")
end