Class: ErrorStalker::Backend::Server

Inherits:
Base
  • Object
show all
Defined in:
lib/error_stalker/backend/server.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Server

Creates a new Server backend instance that will report exceptions to a centralized ErrorStalker server.



24
25
26
27
28
29
# File 'lib/error_stalker/backend/server.rb', line 24

def initialize(params = {})
  @protocol = params[:protocol] || 'http://'
  @host = params[:host] || 'localhost'
  @port = params[:port] || '5678'
  @path = params[:path] || ''
end

Instance Attribute Details

#hostObject

The hostname of the ErrorStalker server



11
12
13
# File 'lib/error_stalker/backend/server.rb', line 11

def host
  @host
end

#pathObject

The path of the ErrorStalker server, if applicable



20
21
22
# File 'lib/error_stalker/backend/server.rb', line 20

def path
  @path
end

#portObject

The ErrorStalker server’s port



14
15
16
# File 'lib/error_stalker/backend/server.rb', line 14

def port
  @port
end

#protocolObject

http or https



17
18
19
# File 'lib/error_stalker/backend/server.rb', line 17

def protocol
  @protocol
end

Instance Method Details

#report(exception_report) ⇒ Object

Reports exception_report to a central ErrorStalker server.



32
33
34
35
36
37
38
39
40
# File 'lib/error_stalker/backend/server.rb', line 32

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