Skip to content

Commit 87fa6a2

Browse files
committed
Merge pull request #121 from intercom/jo/multiple-matching-users-exception
named multiple-matching-users exception
2 parents 10cfd5d + abdcb01 commit 87fa6a2

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

lib/intercom/errors.rb

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class RateLimitExceeded < IntercomError; end
3737

3838
# Raised when the request throws an error not accounted for
3939
class UnexpectedError < IntercomError; end
40+
41+
# Raised when multiple users match the query (typically duplicate email addresses)
42+
class MultipleMatchingUsersError < IntercomError; end
4043

4144
# Raised when you try to call a non-setter method that does not exist on an object
4245
class Intercom::AttributeNotSetError < IntercomError ; end

lib/intercom/request.rb

+2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ def raise_application_errors_on_failure(error_list_details, http_code)
127127
raise Intercom::RateLimitExceeded.new(error_details['message'], error_context)
128128
when 'service_unavailable'
129129
raise Intercom::ServiceUnavailableError.new(error_details['message'], error_context)
130+
when 'conflict'
131+
raise Intercom::MultipleMatchingUsersError.new(error_details['message'], error_context)
130132
when nil, ''
131133
raise Intercom::UnexpectedError.new(message_for_unexpected_error_without_type(error_details, parsed_http_code), error_context)
132134
else

spec/unit/intercom_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
Intercom.app_api_key = nil
1717
proc { Intercom.target_base_url }.must_raise ArgumentError, "You must set both Intercom.app_id and Intercom.app_api_key to use this client. See https://github.com/intercom/intercom-ruby for usage examples."
1818
end
19+
20+
it 'raises an Intercom::MultipleMatchingUsers error when receiving a conflict' do
21+
multiple_matching_error = { 'type' => 'error.list', 'errors' => [{ 'code' => 'conflict', 'message' => 'Multiple existing users match this email address - must be more specific using user_id' }]}
22+
proc {Intercom::Request.new('/users', :get).raise_application_errors_on_failure(multiple_matching_error, 400)}.must_raise(Intercom::MultipleMatchingUsersError)
23+
end
1924

2025
it "returns the app_id and app_api_key previously set" do
2126
Intercom.app_id.must_equal "abc123"

0 commit comments

Comments
 (0)