Sha256: c2ca0b5610de3570508aba29ad2dab33535cc873dfdd4de67b3e66b72e3fea26

Contents?: true

Size: 1023 Bytes

Versions: 1

Compression:

Stored size: 1023 Bytes

Contents

require 'webrick'

module WAB
  module Impl
    module WEBrick

      # The Sender module adds support for sending results and errors.
      module Sender

	# Sends the results from a controller request.
	def send_result(result, res, path, query)
          result = @shell.data(result) unless result.is_a?(WAB::Data)
          response_body = result.json(@shell.indent)
          res.status = 200
          res['Content-Type'] = 'application/json'
          @shell.logger.debug("reply to #{path.join('/')}#{query}: #{response_body}") if @shell.logger.debug?
          res.body = response_body
	end

	# Sends an error from a rescued call.
	def send_error(e, res)
          res.status = 500
          res['Content-Type'] = 'application/json'
          body = { code: -1, error: "#{e.class}: #{e.message}" }
          body[:backtrace] = e.backtrace
          res.body = @shell.data(body).json(@shell.indent)
          @shell.logger.warn(Impl.format_error(e))
	end

      end # Sender
    end # WEBrick
  end # Impl
end # WAB

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wabur-0.7.0 lib/wab/impl/webrick/sender.rb