Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[STRATCONN-5399]-Handles refresh token retry for multistatus responses #2674

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

varadarajan-tw
Copy link
Contributor

@varadarajan-tw varadarajan-tw commented Jan 10, 2025

This PR handles 401 refresh token retries for multistatus responses. Previously, we threw 401 exception for refresh token retries. However, for handling multistatus, developers now return a MultistatusResponse object from performBatch block. This PR ensures that if any of the events in multistatus response has 401 status, the batch will be retried with new refresh token for oauth enabled destinations.

Related but not dependent - https://github.com/segmentio/integrations/pull/3079

Testing

Testing completed successfully in staging - Test Doc

  • Added unit tests for new functionality
  • Tested end-to-end using the local server
  • [If destination is already live] Tested for backward compatibility of destination. Note: New required fields are a breaking change.
  • [Segmenters] Tested in the staging environment
  • [Segmenters] [If applicable for this change] Tested for regression with Hadron.

Copy link

codecov bot commented Jan 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.91%. Comparing base (4888857) to head (778f698).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2674      +/-   ##
==========================================
+ Coverage   78.47%   78.91%   +0.44%     
==========================================
  Files        1032     1085      +53     
  Lines       18590    21252    +2662     
  Branches     3521     4257     +736     
==========================================
+ Hits        14588    16772    +2184     
- Misses       2825     3297     +472     
- Partials     1177     1183       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@varadarajan-tw varadarajan-tw force-pushed the mulistatus-handle-retries branch from 2b4f95c to 57b6f4f Compare January 10, 2025 14:21
@@ -901,7 +901,7 @@ export class Destination<Settings = JSONObject, AudienceSettings = JSONObject> {
return result
}

const onFailedAttempt = async (error: ResponseError & HTTPError) => {
const onFailedAttempt = async (error: ResponseError | HTTPError) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error can either be ResponeError or HTTPError. It can never be a mix of both.

}
return true
}
return await retry<Result[]>(run, { retries: MAX_ATTEMPTS, onFailedAttempt, shouldRetry })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another approach I could have taken is to throw an exception if any of the events failed with 401 error and re-use the existing flow. However, that means we would end up reporting other 400 errors as 401 as well. Therefore, decided to go ahead with this approach of intentionally handling multistatus response. Open to any other thoughts.

@varadarajan-tw varadarajan-tw marked this pull request as ready for review January 13, 2025 16:07
@varadarajan-tw varadarajan-tw requested a review from a team as a code owner January 13, 2025 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants