Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Graphlient::Errors::ConnectionFailedError #68

Merged
merged 3 commits into from
Nov 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### 0.3.7 (Next)
* Your contribution here.
* [#68](https://github.com/ashkan18/graphlient/pull/68): Add `Graphlient::Errors::ConnectionFailedError` - [@neroleung](https://github.com/neroleung).

### 0.3.6 (07/23/2019)

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ Unlike graphql-client, Graphlient will always raise an exception unless the quer
* [Graphlient::Errors::ServerError](lib/graphlient/errors/server_error.rb): all transport errors raised by HTTP Adapters. You can access `inner_exception`, `status_code` and `response` on these errors to get more details on what went wrong
* [Graphlient::Errors::FaradayServerError](lib/graphlient/errors/faraday_server_error.rb): this inherits from `ServerError` ☝️, we recommend using `ServerError` to rescue these
* [Graphlient::Errors::HttpServerError](lib/graphlient/errors/http_server_error.rb): this inherits from `ServerError` ☝️, we recommend using `ServerError` to rescue these
* [Graphlient::Errors::ConnectionFailedError](lib/graphlient/errors/connection_failed_error.rb): this inherits from `ServerError` ☝️, we recommend using `ServerError` to rescue these


All errors inherit from `Graphlient::Errors::Error` if you need to handle them in bulk.
Expand Down
12 changes: 12 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Upgrading Graphlient
===========================

### Upgrading to >= 0.3.7

#### Changes in error handling of connection refused error

Prior to 0.3.7, Graphlient would return `NoMethodError: undefined method []' for nil:NilClass` error if connection is
refused/failed when connecting to a remote host. After 0.3.7, Graphlient will return a new
`Graphlient::Errors::ConnectionFailedError` instead.

See [#68](https://github.com/ashkan18/graphlient/pull/68) for more information.
2 changes: 2 additions & 0 deletions lib/graphlient/adapters/http/faraday_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def execute(document:, operation_name:, variables:, context:)
}.to_json
end
response.body
rescue Faraday::ConnectionFailed => e
raise Graphlient::Errors::ConnectionFailedError, e
rescue Faraday::ClientError => e
raise Graphlient::Errors::FaradayServerError, e
end
Expand Down
1 change: 1 addition & 0 deletions lib/graphlient/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
require_relative 'errors/execution_error'
require_relative 'errors/faraday_server_error'
require_relative 'errors/http_server_error'
require_relative 'errors/connection_failed_error'
6 changes: 6 additions & 0 deletions lib/graphlient/errors/connection_failed_error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Graphlient
module Errors
class ConnectionFailedError < ServerError
end
end
end
21 changes: 21 additions & 0 deletions spec/graphlient/adapters/http/faraday_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,25 @@
expect(client.schema).to be_a Graphlient::Schema
end
end

context 'Failed to open TCP connection error' do
let(:url) { 'http://example.com/graphql' }
let(:client) { Graphlient::Client.new(url) }
let(:error_message) do
'Failed to open TCP connection to localhost:3000 (Connection refused - connect(2) for "localhost" port 3000)'
end

before do
wrapped_error = Errno::ECONNREFUSED.new(error_message)
error = Faraday::ConnectionFailed.new(wrapped_error)

stub_request(:post, url).to_raise(error)
end

specify do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fancy :)

expected_error_message = "Connection refused - #{error_message}"

expect { client.schema }.to raise_error(Graphlient::Errors::ConnectionFailedError, expected_error_message)
end
end
end