From 326f3b4140ff730eab08556f9ed9a4e0045216c5 Mon Sep 17 00:00:00 2001 From: Aubrey Holland Date: Wed, 2 Aug 2017 12:40:42 -0400 Subject: [PATCH] Fixes for Faraday exceptions. Also, make rubocop happy (#9) * catch the correct exceptions * fix rubocop --- .rubocop.yml | 15 ++++++++++----- breakers.gemspec | 1 + lib/breakers/uptime_middleware.rb | 2 +- spec/example_plugin.rb | 12 ++++-------- spec/integration_spec.rb | 10 +++++----- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index d7b3785..3164f95 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,6 +2,8 @@ AllCops: TargetRubyVersion: 2.3 Include: - 'Rakefile' + Exclude: + - Gemfile Metrics/LineLength: Max: 140 @@ -22,6 +24,9 @@ Metrics/ClassLength: Metrics/MethodLength: Max: 50 +Metrics/BlockLength: + Max: 500 + Metrics/AbcSize: Max: 75 @@ -98,7 +103,7 @@ Style/GuardClause: Style/Next: Enabled: false -Style/IndentArray: +Layout/IndentArray: EnforcedStyle: consistent # This forces you to change simple if/unless blocks to the conditional form like: `return 2 if badness`. @@ -149,7 +154,7 @@ Style/WordArray: # Some people really like to put lines at the beginning and end of class bodies, while other people # really don't. It doesn't really seem to matter. -Style/EmptyLinesAroundClassBody: +Layout/EmptyLinesAroundClassBody: Enabled: false # This forces you to put a comment like this at the top of every single file: @@ -164,10 +169,10 @@ Style/Lambda: Enabled: false # Force indentation for milti-line expressions and method calls -Style/MultilineOperationIndentation: +Layout/MultilineOperationIndentation: EnforcedStyle: indented -Style/MultilineMethodCallIndentation: +Layout/MultilineMethodCallIndentation: EnforcedStyle: indented # This disallows the use of $1, $2 from regular expressions, which seems to make no sense whatsoever @@ -198,7 +203,7 @@ Style/ZeroLengthPredicate: # ... # end Lint/EndAlignment: - AlignWith: variable + EnforcedStyleAlignWith: variable # This cop will require you to replace or prefix method arguments that go unused with underscores. The problem # is that while seeming to solve no problem this could easily cause issues where someone editing the code to diff --git a/breakers.gemspec b/breakers.gemspec index 19c4f25..dc99992 100644 --- a/breakers.gemspec +++ b/breakers.gemspec @@ -1,4 +1,5 @@ # coding: utf-8 + lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'breakers/version' diff --git a/lib/breakers/uptime_middleware.rb b/lib/breakers/uptime_middleware.rb index 5b4502e..1e16c2e 100644 --- a/lib/breakers/uptime_middleware.rb +++ b/lib/breakers/uptime_middleware.rb @@ -69,7 +69,7 @@ def handle_request(service:, request_env:, current_outage: nil) end end end - rescue Faraday::Error::TimeoutError => e + rescue Faraday::TimeoutError, Faraday::ConnectionFailed => e handle_error( service: service, request_env: request_env, diff --git a/spec/example_plugin.rb b/spec/example_plugin.rb index 5f5e7db..11b9963 100644 --- a/spec/example_plugin.rb +++ b/spec/example_plugin.rb @@ -1,13 +1,9 @@ class ExamplePlugin - def on_outage_begin(outage) - end + def on_outage_begin(outage); end - def on_outage_end(outage) - end + def on_outage_end(outage); end - def on_error(service, request_env, response_env) - end + def on_error(service, request_env, response_env); end - def on_success(service, request_env, response_env) - end + def on_success(service, request_env, response_env); end end diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 67f58b2..9e9bf8e 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -141,24 +141,24 @@ it 'adds a failure to redis' do begin connection.get '/' - rescue Faraday::TimeoutError + rescue Faraday::ConnectionFailed end rounded_time = now.to_i - (now.to_i % 60) expect(redis.get("VA-errors-#{rounded_time.to_i}").to_i).to eq(1) end it 'raises the exception' do - expect { connection.get '/' }.to raise_error(Faraday::TimeoutError) + expect { connection.get '/' }.to raise_error(Faraday::ConnectionFailed) end it 'logs the error' do expect(logger).to receive(:warn).with( - msg: 'Breakers failed request', service: 'VA', url: 'http://va.gov/', error: 'Faraday::TimeoutError - execution expired' + msg: 'Breakers failed request', service: 'VA', url: 'http://va.gov/', error: 'Faraday::ConnectionFailed - execution expired' ) begin connection.get '/' - rescue Faraday::TimeoutError + rescue Faraday::ConnectionFailed end end @@ -166,7 +166,7 @@ expect(plugin).to receive(:on_error).with(service, instance_of(Faraday::Env), nil) begin connection.get '/' - rescue Faraday::TimeoutError + rescue Faraday::ConnectionFailed end end end