Sha256: c0e32828825a8b538bdfca2678e30eeb1ecd7f77811c1a46e9091bc67b3f44ac

Contents?: true

Size: 617 Bytes

Versions: 1

Compression:

Stored size: 617 Bytes

Contents

require 'json/pure' unless defined? JSON

module WebTools::Support::ServiceHelper
  def self.included(base)
    base.set :show_exceptions, true
    base.set :raise_errors, false

    base.error do
      excep = request.env['sinatra.error']
      { '_stack' => excep.backtrace.join("<br>") }.to_json
    end
  end

  # Returns a JSON string that contains the data under the "data" key.
  # Adds other keys (_time, _stack) if appropriate.
  def prepare_data(data)
    raise "Expecting Hash" unless Hash === data
    data['_time'] = ((Time.now - @ts) * 1_000).to_i
    data['_stack'] = @stack
    data.to_json
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
maglev-webtools-0.2.1 lib/web_tools/support/service_helper.rb