chore: prune the token whenever we receieve a 403 (#33885)

pull/35057/head^2
Gustavo Reis Bauer 12 months ago committed by GitHub
parent 63df8419c1
commit 033db56565
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      .changeset/rude-adults-shout.md
  2. 13
      apps/meteor/app/push/server/fcm.ts

@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": minor
---
Fixes an issue where tokens generated while using the legacy notification provider would never be removed from the database.

@ -54,16 +54,22 @@ type FCMError = {
};
};
// The 403 error code is used when the server is refusing to process a request to a specific token due to
// a SENDER_ID_MISMATCH error. This error is returned when the sender ID provided in the request does not match the sender ID
// associated with the registration token.
const SENDER_ID_MISMATCH_ERROR_CODE = 403;
const NOT_FOUND_ERROR_CODE = 404;
/**
* Send a push notification using Firebase Cloud Messaging (FCM).
* implements the Firebase Cloud Messaging HTTP v1 API, and all of its retry logic,
* see: https://firebase.google.com/docs/reference/fcm/rest/v1/ErrorCode
*
* Errors:
* - For 400, 401, 403 errors: abort, and do not retry.
* - For 400, 401 errors: abort, and do not retry.
* - For 404 errors: remove the token from the database.
* - For 429 errors: retry after waiting for the duration set in the retry-after header. If no retry-after header is set, default to 60 seconds.
* - For 500 errors: retry with exponential backoff.
* - For 5xx errors: retry with exponential backoff.
*/
async function fetchWithRetry(url: string, _removeToken: () => void, options: ExtendedFetchOptions, retries = 0): Promise<Response> {
const MAX_RETRIES = 5;
@ -80,8 +86,7 @@ async function fetchWithRetry(url: string, _removeToken: () => void, options: Ex
const retryAfter = response.headers.get('retry-after');
const retryAfterSeconds = retryAfter ? parseInt(retryAfter, 10) : 60;
if (response.status === 404) {
if ([SENDER_ID_MISMATCH_ERROR_CODE, NOT_FOUND_ERROR_CODE].includes(response.status)) {
_removeToken();
return response;
}

Loading…
Cancel
Save