Sha256: c3754afc1cc30635ddf2f9d221ec82a811e507fc66e87c0144eadc01a6aebdab

Contents?: true

Size: 1.04 KB

Versions: 20

Compression:

Stored size: 1.04 KB

Contents

class CC::Service::Invocation
  class WithErrorHandling
    def initialize(invocation, logger, prefix = nil)
      @invocation = invocation
      @logger = logger
      @prefix = prefix
    end

    def call
      @invocation.call
    rescue CC::Service::HTTPError => e
      @logger.error(error_message(e))
      {
        ok: false,
        params: e.params,
        status: e.status,
        endpoint_url: e.endpoint_url,
        message: e.user_message || e.message,
        log_message: error_message(e)
      }
    rescue => e
      @logger.error(error_message(e))
      {
        ok: false,
        message: e.message,
        log_message: error_message(e)
      }
    end

    private

    def error_message(e)
      if e.respond_to?(:response_body)
        response_body = ". Response: <#{e.response_body.inspect}>"
      else
        response_body = ""
      end

      message  = "Exception invoking service:"
      message << " [#{@prefix}]" if @prefix
      message << " (#{e.class}) #{e.message}"
      message << response_body
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
codeclimate-services-1.6.1 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.6.0 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.5.1 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.5.0 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.4.0 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.3.0 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.2.0 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.1.0 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.0.1 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.0.0 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-0.6.2 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-0.6.1 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-0.6.0 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-0.5.3 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-0.5.2 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-0.5.1 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-0.5.0 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-0.4.1 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-0.4.0 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-0.3.0 lib/cc/service/invocation/with_error_handling.rb