lib/grape/error_formatter/txt.rb in grape-2.0.0 vs lib/grape/error_formatter/txt.rb in grape-2.1.0
- old
+ new
@@ -8,19 +8,20 @@
class << self
def call(message, backtrace, options = {}, env = nil, original_exception = nil)
message = present(message, env)
result = message.is_a?(Hash) ? ::Grape::Json.dump(message) : message
- rescue_options = options[:rescue_options] || {}
- if rescue_options[:backtrace] && backtrace && !backtrace.empty?
- result += "\r\n backtrace:"
- result += backtrace.join("\r\n ")
- end
- if rescue_options[:original_exception] && original_exception
- result += "\r\n original exception:"
- result += "\r\n #{original_exception.inspect}"
- end
- result
+ 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
end
end
end
end