Skip to content

Commit 89d978d

Browse files
authored
Raise ResourceNotFound when company is not found (fixes #484) (#485)
Raise ResourceNotFound when company is not found (fixes #484)
2 parents 3e2c24f + 4d20387 commit 89d978d

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

lib/intercom/request.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def raise_application_errors_on_failure(error_list_details, http_code)
171171
raise Intercom::BadRequestError.new(error_details['message'], error_context)
172172
when "not_restorable"
173173
raise Intercom::BlockedUserError.new(error_details['message'], error_context)
174-
when "not_found"
174+
when "not_found", "company_not_found"
175175
raise Intercom::ResourceNotFound.new(error_details['message'], error_context)
176176
when "admin_not_found"
177177
raise Intercom::AdminNotFound.new(error_details['message'], error_context)

spec/unit/intercom/request_spec.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
req = Intercom::Request.get(uri, "")
3838
req.handle_rate_limit=true
3939
req.expects(:sleep).times(3).with(any_parameters)
40-
req.execute(target_base_url=uri, username: "ted", secret: "")
40+
req.execute(uri, username: "ted", secret: "")
4141
}.must_raise(Intercom::RateLimitExceeded)
4242
end
4343

@@ -48,7 +48,7 @@
4848
req = Intercom::Request.get(uri, "")
4949
req.handle_rate_limit=true
5050
req.expects(:sleep).never.with(any_parameters)
51-
req.execute(target_base_url=uri, username: "ted", secret: "")
51+
req.execute(uri, username: "ted", secret: "")
5252
end
5353

5454
it 'should call sleep for rate limit error just once' do
@@ -59,7 +59,7 @@
5959
req = Intercom::Request.get(uri, "")
6060
req.handle_rate_limit=true
6161
req.expects(:sleep).with(any_parameters)
62-
req.execute(target_base_url=uri, username: "ted", secret: "")
62+
req.execute(uri, username: "ted", secret: "")
6363
end
6464

6565
it 'should not sleep if rate limit reset time has passed' do
@@ -70,7 +70,7 @@
7070
req = Intercom::Request.get(uri, "")
7171
req.handle_rate_limit=true
7272
req.expects(:sleep).never.with(any_parameters)
73-
req.execute(target_base_url=uri, username: "ted", secret: "")
73+
req.execute(uri, username: "ted", secret: "")
7474
end
7575
end
7676

@@ -82,7 +82,7 @@
8282
stub_request(:put, uri).\
8383
to_return(status: [409, "Resource Already Exists"], headers: { 'X-RateLimit-Reset' => (Time.now.utc + 10).to_i.to_s }, body: {type: "error.list", errors: [ code: "resource_conflict" ]}.to_json)
8484
req = Intercom::Request.put(uri, "")
85-
expect { req.execute(target_base_url=uri, username: "ted", secret: "") }.must_raise(Intercom::ResourceNotUniqueError)
85+
expect { req.execute(uri, username: "ted", secret: "") }.must_raise(Intercom::ResourceNotUniqueError)
8686
end
8787

8888
it 'should raise ApiVersionInvalid error on intercom_version_invalid code' do
@@ -92,6 +92,13 @@
9292
req = Intercom::Request.put(uri, "")
9393
expect { req.execute(uri, username: "ted", secret: "") }.must_raise(Intercom::ApiVersionInvalid)
9494
end
95+
96+
it 'should raise ResourceNotFound error on company_not_found code' do
97+
stub_request(:put, uri).\
98+
to_return(status: [404, "Not Found"], headers: { 'X-RateLimit-Reset' => (Time.now.utc + 10).to_i.to_s }, body: {type: "error.list", errors: [ code: "company_not_found" ]}.to_json)
99+
req = Intercom::Request.put(uri, "")
100+
expect { req.execute(uri, username: "ted", secret: "") }.must_raise(Intercom::ResourceNotFound)
101+
end
95102
end
96103

97104
it 'parse_body returns nil if decoded_body is nil' do

0 commit comments

Comments
 (0)