Skip to content

Commit

Permalink
Fixes for Faraday exceptions. Also, make rubocop happy (#9)
Browse files Browse the repository at this point in the history
* catch the correct exceptions

* fix rubocop
  • Loading branch information
aub authored and robbiethegeek-usds committed Aug 2, 2017
1 parent 46b36b8 commit 326f3b4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
15 changes: 10 additions & 5 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ AllCops:
TargetRubyVersion: 2.3
Include:
- 'Rakefile'
Exclude:
- Gemfile

Metrics/LineLength:
Max: 140
Expand All @@ -22,6 +24,9 @@ Metrics/ClassLength:
Metrics/MethodLength:
Max: 50

Metrics/BlockLength:
Max: 500

Metrics/AbcSize:
Max: 75

Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions breakers.gemspec
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion lib/breakers/uptime_middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 4 additions & 8 deletions spec/example_plugin.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,32 +141,32 @@
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

it 'tells plugins about the timeout' do
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
Expand Down

0 comments on commit 326f3b4

Please sign in to comment.