lib/intercom/request.rb in intercom-3.5.23 vs lib/intercom/request.rb in intercom-3.5.24

- old
+ new

@@ -72,11 +72,12 @@ parsed_body = parse_body(decoded_body, response) raise_errors_on_failure(response) parsed_body rescue Intercom::RateLimitExceeded => e if @handle_rate_limit - sleep (@rate_limit_details[:reset_at] - Time.now.utc).ceil + seconds_to_retry = (@rate_limit_details[:reset_at] - Time.now.utc).ceil + sleep seconds_to_retry unless seconds_to_retry < 0 retry unless (retries -=1).zero? else raise e end rescue Timeout::Error @@ -107,11 +108,11 @@ def set_rate_limit_details(response) rate_limit_details = {} rate_limit_details[:limit] = response['X-RateLimit-Limit'].to_i if response['X-RateLimit-Limit'] rate_limit_details[:remaining] = response['X-RateLimit-Remaining'].to_i if response['X-RateLimit-Remaining'] - rate_limit_details[:reset_at] = Time.at(response['X-RateLimit-Reset'].to_i) if response['X-RateLimit-Reset'] + rate_limit_details[:reset_at] = Time.parse(response['X-RateLimit-Reset']) if response['X-RateLimit-Reset'] @rate_limit_details = rate_limit_details end def decode(content_encoding, body) return body if (!body) || body.empty? || content_encoding != 'gzip' @@ -149,9 +150,15 @@ :request_id => error_list_details['request_id'] } case error_code when 'unauthorized', 'forbidden', 'token_not_found' raise Intercom::AuthenticationError.new(error_details['message'], error_context) + when 'token_suspended' + raise Intercom::AppSuspendedError.new(error_details['message'], error_context) + when 'token_revoked' + raise Intercom::TokenRevokedError.new(error_details['message'], error_context) + when 'token_unauthorized' + raise Intercom::TokenUnauthorizedError.new(error_details['message'], error_context) when "bad_request", "missing_parameter", 'parameter_invalid', 'parameter_not_found' raise Intercom::BadRequestError.new(error_details['message'], error_context) when "not_restorable" raise Intercom::BlockedUserError.new(error_details['message'], error_context) when "not_found"