Skip to content

Commit 2bb3cfb

Browse files
committed
Add extra context to IntercomError
* request_id that helps when contacting intercom support * 'field' that denotes the cause of a validation error
1 parent a81d155 commit 2bb3cfb

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lib/intercom/errors.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ module Intercom
22

33
# Base class exception from which all public Intercom exceptions will be derived
44
class IntercomError < StandardError
5-
attr_reader :http_code, :application_error_code
6-
def initialize(message, http_code = nil, error_code = application_error_code)
7-
@http_code = http_code
8-
@application_error_code = error_code
5+
attr_reader :http_code, :application_error_code, :field, :request_id
6+
def initialize(message, context={})
7+
@http_code = context[:http_code]
8+
@application_error_code = context[:application_error_code]
9+
@field = context[:field]
10+
@request_id = context[:request_id]
911
super(message)
1012
end
1113
end

lib/intercom/request.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def execute(target_base_url=nil)
7474
raise Intercom::ServiceConnectionError.new('Failed to connect to service [connection attempt timed out]')
7575
end
7676
end
77-
77+
7878
def decode_body(response)
7979
decode(response['content-encoding'], response.body)
8080
end
@@ -124,10 +124,13 @@ def raise_application_errors_on_failure(error_list_details, http_code)
124124
# Currently, we don't support multiple errors
125125
error_details = error_list_details['errors'].first
126126
error_code = error_details['type'] || error_details['code']
127+
error_field = error_details['field']
127128
parsed_http_code = (http_code > 0 ? http_code : nil)
128129
error_context = {
129130
:http_code => parsed_http_code,
130-
:application_error_code => error_code
131+
:application_error_code => error_code,
132+
:field => error_field,
133+
:request_id => error_list_details['request_id']
131134
}
132135
case error_code
133136
when 'unauthorized', 'forbidden'

0 commit comments

Comments
 (0)