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

Fix request timeout #188

Merged
merged 2 commits into from
Aug 26, 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
2 changes: 1 addition & 1 deletion lib/auth0/mixins/httpproxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def call(method, url, timeout, headers, body = nil)
rescue RestClient::Exception => e
case e
when RestClient::RequestTimeout
raise Auth0::RequestTimeout
raise Auth0::RequestTimeout.new(e.message)
else
return e.response
end
Expand Down
26 changes: 24 additions & 2 deletions spec/lib/auth0/mixins/httpproxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,19 @@
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::Unsupported)
end

it "should raise Auth0::RequestTimeout on send http #{http_method} method
to path defined through HTTP when RestClient::RequestTimeout received" do
allow(RestClient::Request).to receive(:execute).with(method: http_method,
url: '/test',
timeout: nil,
headers: { params: {} },
payload: nil)
.and_raise(RestClient::Exceptions::OpenTimeout.new)
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::RequestTimeout)
end

it "should raise Auth0::BadRequest on send http #{http_method} method
to path defined through HTTP when 400 or other unknown status received" do
to path defined through HTTP when 400 status received" do
@exception.response = StubResponse.new({}, false, 400)
allow(RestClient::Request).to receive(:execute).with(method: http_method,
url: '/test',
Expand Down Expand Up @@ -230,8 +241,19 @@
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::Unsupported)
end

it "should raise Auth0::RequestTimeout on send http #{http_method} method
to path defined through HTTP when RestClient::RequestTimeout received" do
allow(RestClient::Request).to receive(:execute).with(method: http_method,
url: '/test',
timeout: nil,
headers: nil,
payload: '{}')
.and_raise(RestClient::Exceptions::OpenTimeout.new)
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::RequestTimeout)
end

it "should raise Auth0::BadRequest on send http #{http_method} method
to path defined through HTTP when 400 or other unknown status received" do
to path defined through HTTP when 400 status received" do
@exception.response = StubResponse.new({}, false, 400)
allow(RestClient::Request).to receive(:execute).with(method: http_method,
url: '/test',
Expand Down