lib/alephant/publisher/request/data_mapper_factory.rb in alephant-publisher-request-0.2.2 vs lib/alephant/publisher/request/data_mapper_factory.rb in alephant-publisher-request-0.2.3

- old
+ new

@@ -1,12 +1,12 @@ -require 'alephant/logger' +require 'alephant/publisher/request/log_helper' module Alephant module Publisher module Request class DataMapperFactory - include Logger + include Alephant::Publisher::Request::LogHelper attr_reader :connection, :base_path def initialize(connection, base_path) @connection = connection @@ -17,18 +17,18 @@ def create(component_id, context = {}) require base_path_for component_id klass = mapper_class_for(component_id) klass.new(connection, context) - rescue LoadError - logger.metric(:name => "PublisherRequestDataMapperFactoryInvalidComponentName", :unit => "Count", :value => 1) + rescue LoadError => e + log_error_with_metric(e, component_id, "PublisherRequestDataMapperFactoryInvalidComponentName") raise InvalidComponentName, "Invalid component name: #{component_id}" - rescue NameError - logger.metric(:name => "PublisherRequestDataMapperFactoryInvalidComponentClassName", :unit => "Count", :value => 1) + rescue NameError => e + log_error_with_metric(e, component_id, "PublisherRequestDataMapperFactoryInvalidComponentClassName") raise InvalidComponentClassName, "Invalid class name #{klass}" - rescue - logger.metric(:name => "PublisherRequestDataMapperFactoryInvalidComponent", :unit => "Count", :value => 1) + rescue => e + log_error_with_metric(e, component_id, "PublisherRequestDataMapperFactoryInvalidComponent") raise InvalidComponent, "Name: #{component_id}, Class: #{klass}" end protected @@ -42,9 +42,12 @@ def mapper_class_for(component_id) Object.const_get("#{camalize component_id}Mapper") end + def log_error(e, component_id, metric) + log_error_with_metric(e, 'DataMapperFactory#create', component_id, metric) + end end end end end