Sha256: d51d9f45451221f370d4d8466644684e4e7666082849b1c3e23e96be52b9586b

Contents?: true

Size: 1.75 KB

Versions: 46

Compression:

Stored size: 1.75 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

module NewRelic
  module Agent
    class NewRelicService
      class Marshaller
        def parsed_error(error)
          error_type    = error['error_type']
          error_message = error['message']

          exception = case error_type
          when 'NewRelic::Agent::LicenseException'
            LicenseException.new(error_message)
          when 'NewRelic::Agent::ForceRestartException'
            ForceRestartException.new(error_message)
          when 'NewRelic::Agent::ForceDisconnectException'
            ForceDisconnectException.new(error_message)
          else
            CollectorError.new("#{error['error_type']}: #{error['message']}")
          end

          exception
        end

        def prepare(data, options={})
          encoder = options[:encoder] || default_encoder
          if data.respond_to?(:to_collector_array)
            data.to_collector_array(encoder)
          elsif data.kind_of?(Array)
            data.map { |element| prepare(element, options) }
          else
            data
          end
        end

        def default_encoder
          Encoders::Identity
        end

        def self.human_readable?
          false
        end

        protected

        def return_value(data)
          if data.respond_to?(:has_key?)
            if data.has_key?('exception')
              raise parsed_error(data['exception'])
            elsif data.has_key?('return_value')
              return data['return_value']
            end
          end
          ::NewRelic::Agent.logger.debug("Unexpected response from collector: #{data}")
          nil
        end
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 2 rubygems

Version Path
newrelic_rpm-6.0.0.351 lib/new_relic/agent/new_relic_service/marshaller.rb
newrelic_rpm-5.7.0.350 lib/new_relic/agent/new_relic_service/marshaller.rb
newrelic_rpm-5.6.0.349 lib/new_relic/agent/new_relic_service/marshaller.rb
newrelic_rpm-5.5.0.348 lib/new_relic/agent/new_relic_service/marshaller.rb
newrelic_rpm-5.4.0.347 lib/new_relic/agent/new_relic_service/marshaller.rb
newrelic_rpm-5.3.0.346 lib/new_relic/agent/new_relic_service/marshaller.rb
newrelic_rpm-5.2.0.345 lib/new_relic/agent/new_relic_service/marshaller.rb
newrelic_rpm-5.1.0.344 lib/new_relic/agent/new_relic_service/marshaller.rb
newrelic_rpm-5.0.0.342 lib/new_relic/agent/new_relic_service/marshaller.rb
newrelic_rpm-4.8.0.341 lib/new_relic/agent/new_relic_service/marshaller.rb
newrelic_rpm-4.7.1.340 lib/new_relic/agent/new_relic_service/marshaller.rb
newrelic_rpm-4.7.0.339 lib/new_relic/agent/new_relic_service/marshaller.rb
newrelic_rpm-4.6.0.338 lib/new_relic/agent/new_relic_service/marshaller.rb
newrelic_rpm-4.5.0.337 lib/new_relic/agent/new_relic_service/marshaller.rb
newrelic_rpm-4.4.0.336 lib/new_relic/agent/new_relic_service/marshaller.rb
newrelic_rpm-4.3.0.335 lib/new_relic/agent/new_relic_service/marshaller.rb
newrelic_rpm-4.2.0.334 lib/new_relic/agent/new_relic_service/marshaller.rb
newrelic_rpm-4.1.0.333 lib/new_relic/agent/new_relic_service/marshaller.rb
newrelic_rpm-4.0.0.332 lib/new_relic/agent/new_relic_service/marshaller.rb
newrelic_rpm-3.18.1.330 lib/new_relic/agent/new_relic_service/marshaller.rb