Sha256: 8db4a86ed237b6e3168c0d1482ea3c61eb356e9c7229c3690ef9a4ec32d51dbd

Contents?: true

Size: 1.36 KB

Versions: 18

Compression:

Stored size: 1.36 KB

Contents

describe CC::Service::Invocation::WithErrorHandling do
  it "success returns upstream result" do
    handler = CC::Service::Invocation::WithErrorHandling.new(
      -> { :success },
      FakeLogger.new,
      "not important",
    )

    expect(handler.call).to eq(:success)
  end

  it "http errors return relevant data" do
    logger = FakeLogger.new
    env = {
      status: 401,
      params: "params",
      url: "url",
    }

    handler = CC::Service::Invocation::WithErrorHandling.new(
      -> { raise CC::Service::HTTPError.new("foo", env) },
      logger,
      "prefix",
    )

    result = handler.call
    expect(result[:ok]).to eq(false)
    expect(result[:status]).to eq(401)
    expect(result[:params]).to eq("params")
    expect(result[:endpoint_url]).to eq("url")
    expect(result[:message]).to eq("foo")
    expect(result[:log_message]).to eq("Exception invoking service: [prefix] (CC::Service::HTTPError) foo. Response: <nil>")
  end

  it "error returns a hash with explanations" do
    logger = FakeLogger.new

    handler = CC::Service::Invocation::WithErrorHandling.new(
      -> { raise ArgumentError, "lol" },
      logger,
      "prefix",
    )

    result = handler.call
    expect(result[:ok]).to eq(false)
    expect(result[:message]).to eq("lol")
    expect(result[:log_message]).to eq("Exception invoking service: [prefix] (ArgumentError) lol")
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

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