Sha256: 76acc37b9daa3747b659ba8e18e858226383850f9e1d108db86e9327037ac35b

Contents?: true

Size: 1.47 KB

Versions: 26

Compression:

Stored size: 1.47 KB

Contents

require 'net/http'
require 'json'
require 'zlib'
require 'openssl'

require 'honeybadger/backend/base'
require 'honeybadger/util/http'

module Honeybadger
  module Backend
    class Server < Base
      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

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

      # 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.
      def notify(feature, payload)
        ENDPOINTS[feature] or raise(BackendError, "Unknown feature: #{feature}")
        Response.new(@http.post(ENDPOINTS[feature], 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
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
honeybadger-2.1.0.beta.1 lib/honeybadger/backend/server.rb
honeybadger-2.0.12 lib/honeybadger/backend/server.rb
honeybadger-2.0.11 lib/honeybadger/backend/server.rb
honeybadger-2.0.10 lib/honeybadger/backend/server.rb
honeybadger-2.0.9 lib/honeybadger/backend/server.rb
honeybadger-2.0.8 lib/honeybadger/backend/server.rb
honeybadger-2.0.6 lib/honeybadger/backend/server.rb
honeybadger-2.0.5 lib/honeybadger/backend/server.rb
honeybadger-2.0.4 lib/honeybadger/backend/server.rb
honeybadger-2.0.3 lib/honeybadger/backend/server.rb
honeybadger-2.0.2 lib/honeybadger/backend/server.rb
honeybadger-2.0.1 lib/honeybadger/backend/server.rb
honeybadger-2.0.0 lib/honeybadger/backend/server.rb
honeybadger-2.0.0.beta.13 lib/honeybadger/backend/server.rb
honeybadger-2.0.0.beta.12 lib/honeybadger/backend/server.rb
honeybadger-2.0.0.beta.11 lib/honeybadger/backend/server.rb
honeybadger-2.0.0.beta.10 lib/honeybadger/backend/server.rb
honeybadger-2.0.0.beta.9 lib/honeybadger/backend/server.rb
honeybadger-2.0.0.beta.8 lib/honeybadger/backend/server.rb
honeybadger-2.0.0.beta.7 lib/honeybadger/backend/server.rb