Sha256: 418cf8e08363e7abdbae9e4c52bcdccbb3e71f10c87c420df8516f90439267b1

Contents?: true

Size: 1.25 KB

Versions: 5

Compression:

Stored size: 1.25 KB

Contents

require 'json'
require 'net/http'

# Stores reported exceptions to a central ErrorStalker server (a Rack
# server pointing to an ErrorStalker::Server instance). The most
# complicated ErrorStalker backend, it is also the most powerful. This
# is probably what you want to be using in production.
class ErrorStalker::Backend::Server < ErrorStalker::Backend::Base

  # The hostname of the ErrorStalker server
  attr_accessor :host

  # The ErrorStalker server's port
  attr_accessor :port

  # http or https
  attr_accessor :protocol

  # The path of the ErrorStalker server, if applicable
  attr_accessor :path 
  
  # Creates a new Server backend instance that will report exceptions
  # to a centralized ErrorStalker server.
  def initialize(params = {})
    @protocol = params[:protocol] || 'http://'
    @host = params[:host] || 'localhost'
    @port = params[:port] || '5678'
    @path = params[:path] || ''
  end

  # Reports +exception_report+ to a central ErrorStalker server.
  def report(exception_report)
    req = Net::HTTP::Post.new("#{path}/report.json")
    req["content-type"] = "application/json"
    req.body = exception_report.to_json
    http = Net::HTTP.new(host, port)
    http.read_timeout = 10
    res = http.start { |http| http.request(req) }
    res
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
error_stalker-0.0.16 lib/error_stalker/backend/server.rb
error_stalker-0.0.15 lib/error_stalker/backend/server.rb
error_stalker-0.0.14 lib/error_stalker/backend/server.rb
error_stalker-0.0.13 lib/error_stalker/backend/server.rb
error_stalker-0.0.12 lib/error_stalker/backend/server.rb