Skip to content

Commit

Permalink
Merge pull request oesmith#228 from cupakromer/catch-unhandled-reques…
Browse files Browse the repository at this point in the history
…t-errors

Catch unhandled request handler errors
  • Loading branch information
ronwsmith authored Mar 5, 2018
2 parents 28800a9 + 6a117d8 commit 6f257f3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/billy/handlers/request_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def handle_request(method, url, headers, body)

body_msg = Billy.config.cache_request_body_methods.include?(method) ? " with body '#{body}'" : ''
{ error: "Connection to #{url}#{body_msg} not cached and new http connections are disabled" }
rescue => error
{ error: error.message }
end

def handles_request?(method, url, headers, body)
Expand Down
15 changes: 15 additions & 0 deletions spec/lib/billy/handlers/request_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@
expect(proxy_handler).to receive(:handle_request).with(*args)
expect(subject.handle_request(*args)).to eql(error: "Connection to url with body 'body' not cached and new http connections are disabled")
end

it 'returns an error hash on unhandled exceptions' do
# Allow handling requests initially
allow(stub_handler).to receive(:handle_request)
allow(cache_handler).to receive(:handle_request)

allow(proxy_handler).to receive(:handle_request).and_raise("Any Proxy Error")
expect(subject.handle_request(*args)).to eql(error: "Any Proxy Error")

allow(cache_handler).to receive(:handle_request).and_raise("Any Cache Error")
expect(subject.handle_request(*args)).to eql(error: "Any Cache Error")

allow(stub_handler).to receive(:handle_request).and_raise("Any Stub Error")
expect(subject.handle_request(*args)).to eql(error: "Any Stub Error")
end
end

describe '#stub' do
Expand Down

0 comments on commit 6f257f3

Please sign in to comment.