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

Handle 409 conflict errors with its own exception class #640

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions lib/auth0/exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,7 @@ def reset
end

class InvalidIdToken < Auth0::Exception; end
# When trying to create a resource that already exists
# e.g: an organization with the same name
class Conflict < Auth0::HTTPError; end
end
1 change: 1 addition & 0 deletions lib/auth0/mixins/httpproxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def request(method, uri, body = {}, extra_headers = {})
when 401 then raise Auth0::Unauthorized.new(result.body, code: result.code, headers: result.headers)
when 403 then raise Auth0::AccessDenied.new(result.body, code: result.code, headers: result.headers)
when 404 then raise Auth0::NotFound.new(result.body, code: result.code, headers: result.headers)
when 409 then raise Auth0::Conflict.new(result.body, code: result.code, headers: result.headers)
when 429 then raise Auth0::RateLimitEncountered.new(result.body, code: result.code, headers: result.headers)
when 500 then raise Auth0::ServerError.new(result.body, code: result.code, headers: result.headers)
else raise Auth0::Unsupported.new(result.body, code: result.code, headers: result.headers)
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/auth0/mixins/httpproxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,14 @@ def expected_payload(method, overrides = {})
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::NotFound, res)
end

it "should raise Auth0::Conflict on send http #{http_method} method
to path defined through HTTP when 409 status received" do
@exception.response = StubResponse.new({}, false, 409)
allow(RestClient::Request).to receive(:execute).with(expected_payload(http_method))
.and_raise(@exception)
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::Conflict)
end

context "when status 429 is recieved on send http #{http_method} method" do
it "should retry 3 times when retry_count is not set" do
retry_instance = DummyClassForProxy.new
Expand Down