Class: Honeybadger::Backend::Server

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

Constant Summary collapse

ENDPOINTS =
{
  ping: '/v1/ping'.freeze,
  notices: '/v1/notices'.freeze,
  metrics: '/v1/metrics'.freeze,
  traces: '/v1/traces'.freeze,
  deploys: '/v1/deploys'.freeze
}.freeze
HTTP_ERRORS =
[Timeout::Error,
Errno::EINVAL,
Errno::ECONNRESET,
EOFError,
Net::HTTPBadResponse,
Net::HTTPHeaderSyntaxError,
Net::ProtocolError,
Errno::ECONNREFUSED,
SocketError].freeze

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Server

Returns a new instance of Server.



30
31
32
33
# File 'lib/honeybadger/backend/server.rb', line 30

def initialize(config)
  @http = Util::HTTP.new(config)
  super
end

Instance Method Details

#notify(feature, payload) ⇒ Object

Internal: Post payload to endpoint for feature.

feature - The feature which is being notified. payload - The payload to send, responding to ‘#to_json`.

Returns Response.



41
42
43
44
45
46
47
48
# File 'lib/honeybadger/backend/server.rb', line 41

def notify(feature, payload)
  ENDPOINTS[feature] or raise(BackendError, "Unknown feature: #{feature}")
  Response.new(@http.post(ENDPOINTS[feature], payload, payload_headers(payload)))
rescue *HTTP_ERRORS => e
  Response.new(:error, nil, "HTTP Error: #{e.class}").tap do |response|
    error { sprintf('http error class=%s message=%s', e.class, e.message.dump) }
  end
end