Skip to content

Commit 22ea915

Browse files
authored
Merge pull request #2311 from openstax/fix_payments_spam
Fix Tutor spamming payments with token requests if 403 keeps happening
2 parents e3f351b + 01ff42d commit 22ea915

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/openstax/payments/api/real_client.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,13 @@ def absolutize_url(url)
6969
Addressable::URI.join @server_url, url.to_s
7070
end
7171

72-
def api_request(method:, url:, body: {})
72+
def api_request(method:, url:, body: nil)
7373
absolute_uri = absolutize_url(url)
7474

75-
request_options = HEADER_OPTIONS.merge({ body: body.to_json })
75+
request_options = HEADER_OPTIONS.merge(body.nil? ? {} : { body: body.to_json })
7676

7777
begin
78-
num_tries ||= 0
79-
num_tries += 1
78+
num_retries ||= 0
8079
response = oauth_worker.request(method, absolute_uri, request_options)
8180
rescue OAuth2::Error => err
8281
if err.try(:response).try(:status) == 403
@@ -87,7 +86,8 @@ def api_request(method:, url:, body: {})
8786
# date can be changed on Payments without us knowing, we always try to get
8887
# a new token even if not expired.
8988

90-
if num_tries >= 1
89+
if num_retries < 1
90+
num_retries += 1
9191
Rails.logger.info('OX Payments: client token expired') if token_expired?
9292
Rails.logger.info('OX Payments: getting a new token to try to resolve a 403')
9393
initialize_oauth_variables! force: true # resets token

0 commit comments

Comments
 (0)