bellycard/napa

View on GitHub
lib/napa/grape_extensions/error_formatter.rb

Summary

Maintainability
A
35 mins
Test Coverage
if defined?(Grape)
  module Grape
    module ErrorFormatter
      module Json
        class << self
          def call(message, backtrace, options = {}, _env = nil)
            result = message.is_a?(Napa::JsonError) ? message : Napa::JsonError.new(:api_error, message)

            if (options[:rescue_options] || {})[:backtrace] && backtrace && !backtrace.empty?
              result = result.to_h.merge(backtrace: backtrace)
            end
            MultiJson.dump(result)
          end
        end
      end
    end
  end
end