Sha256: 761d3e0ee2b3da0f5cfde041f1710018fc12cabe1b6f22aed945a9861be54465

Contents?: true

Size: 1.04 KB

Versions: 18

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)
      response_body =
        if e.respond_to?(:response_body)
          ". Response: <#{e.response_body.inspect}>"
        else
          ""
        end

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

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
codeclimate-services-1.11.4 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.11.3 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.11.2 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.11.1 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.11.0 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.10.1 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.10.0 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.9.8 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.9.7 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.9.6 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.9.5 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.9.4 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.9.3 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.9.2 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.9.1 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.9.0 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.8.0 lib/cc/service/invocation/with_error_handling.rb
codeclimate-services-1.7.0 lib/cc/service/invocation/with_error_handling.rb