Skip to content

Commit 80df2ed

Browse files
authored
Merge pull request #19675 from Expensify/maxence-rracfa
Remove shouldRetry and canCancel now that deprecatedAPI is gone
2 parents 6ac604f + e6089d6 commit 80df2ed

File tree

12 files changed

+26
-50
lines changed

12 files changed

+26
-50
lines changed

src/CONST.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,9 @@ const CONST = {
747747
MAX_RETRY_WAIT_TIME_MS: 10 * 1000,
748748
PROCESS_REQUEST_DELAY_MS: 1000,
749749
MAX_PENDING_TIME_MS: 10 * 1000,
750+
COMMAND: {
751+
LOG: 'Log',
752+
},
750753
},
751754
DEFAULT_TIME_ZONE: {automatic: true, selected: 'America/Los_Angeles'},
752755
DEFAULT_ACCOUNT_DATA: {errors: null, success: '', isLoading: false},

src/libs/API.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ function write(command, apiCommandParameters = {}, onyxData = {}) {
6161
command,
6262
data: {
6363
...data,
64-
65-
// This should be removed once we are no longer using deprecatedAPI https://github.com/Expensify/Expensify/issues/215650
66-
shouldRetry: true,
67-
canCancel: true,
6864
},
6965
..._.omit(onyxData, 'optimisticData'),
7066
};

src/libs/Authentication.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ function Authenticate(parameters) {
3636
partnerUserSecret: parameters.partnerUserSecret,
3737
twoFactorAuthCode: parameters.twoFactorAuthCode,
3838
authToken: parameters.authToken,
39-
shouldRetry: false,
4039

4140
// Force this request to be made because the network queue is paused when re-authentication is happening
4241
forceNetworkRequest: true,

src/libs/HttpUtils.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ let cancellationController = new AbortController();
2929
* @param {String} url
3030
* @param {String} [method]
3131
* @param {Object} [body]
32-
* @param {Boolean} [canCancel]
32+
* @param {String} [command]
3333
* @returns {Promise}
3434
*/
35-
function processHTTPRequest(url, method = 'get', body = null, canCancel = true) {
35+
function processHTTPRequest(url, method = 'get', body = null, command = '') {
36+
const signal = command === CONST.NETWORK.COMMAND.LOG ? undefined : cancellationController.signal;
37+
3638
return fetch(url, {
3739
// We hook requests to the same Controller signal, so we can cancel them all at once
38-
signal: canCancel ? cancellationController.signal : undefined,
40+
signal,
3941
method,
4042
body,
4143
})
@@ -127,7 +129,7 @@ function xhr(command, data, type = CONST.NETWORK.METHOD.POST, shouldUseSecure =
127129
});
128130

129131
const url = ApiUtils.getCommandURL({shouldUseSecure, command});
130-
return processHTTPRequest(url, type, formData, data.canCancel);
132+
return processHTTPRequest(url, type, formData, command);
131133
}
132134

133135
function cancelPendingRequests() {

src/libs/Log.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import getPlatform from './getPlatform';
66
import pkg from '../../package.json';
77
import requireParameters from './requireParameters';
88
import * as Network from './Network';
9+
import CONST from '../CONST';
910

1011
let timeout = null;
1112

@@ -16,12 +17,11 @@ let timeout = null;
1617
* @returns {Promise}
1718
*/
1819
function LogCommand(parameters) {
19-
const commandName = 'Log';
20+
const commandName = CONST.NETWORK.COMMAND.LOG;
2021
requireParameters(['logPacket', 'expensifyCashAppVersion'], parameters, commandName);
2122

2223
// Note: We are forcing Log to run since it requires no authToken and should only be queued when we are offline.
23-
// Non-cancellable request: during logout, when requests are cancelled, we don't want to cancel any remaining logs
24-
return Network.post(commandName, {...parameters, forceNetworkRequest: true, canCancel: false});
24+
return Network.post(commandName, {...parameters, forceNetworkRequest: true});
2525
}
2626

2727
/**
@@ -36,7 +36,6 @@ function LogCommand(parameters) {
3636
function serverLoggingCallback(logger, params) {
3737
const requestParams = params;
3838
requestParams.shouldProcessImmediately = false;
39-
requestParams.shouldRetry = false;
4039
requestParams.expensifyCashAppVersion = `expensifyCash[${getPlatform()}]${pkg.version}`;
4140
if (requestParams.parameters) {
4241
requestParams.parameters = JSON.stringify(params.parameters);

src/libs/Middleware/Logging.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import CONST from '../../CONST';
1010
*/
1111
function logRequestDetails(message, request, response = {}) {
1212
// Don't log about log or else we'd cause an infinite loop
13-
if (request.command === 'Log') {
13+
if (request.command === CONST.NETWORK.COMMAND.LOG) {
1414
return;
1515
}
1616

@@ -65,7 +65,7 @@ function Logging(response, request) {
6565
} else if (error.message === CONST.ERROR.FAILED_TO_FETCH) {
6666
// If the command that failed is Log it's possible that the next call to Log may also fail.
6767
// This will lead to infinitely complex log params that can eventually crash the app.
68-
if (request.command === 'Log') {
68+
if (request.command === CONST.NETWORK.COMMAND.LOG) {
6969
delete logParams.request;
7070
}
7171

src/libs/Middleware/Reauthentication.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,30 +58,18 @@ function Reauthentication(response, request, isFromSequentialQueue) {
5858
// There are some API requests that should not be retried when there is an auth failure like
5959
// creating and deleting logins. In those cases, they should handle the original response instead
6060
// of the new response created by handleExpiredAuthToken.
61-
const shouldRetry = lodashGet(request, 'data.shouldRetry');
61+
// If the request was from the sequential queue we don't want to return, we want to run the reauthentication callback and retry the request
6262
const apiRequestType = lodashGet(request, 'data.apiRequestType');
63-
64-
// For the SignInWithShortLivedAuthToken command, if the short token expires, the server returns a 407 error,
65-
// and credentials are still empty at this time, which causes reauthenticate to throw an error (requireParameters),
66-
// and the subsequent SaveResponseInOnyx also cannot be executed, so we need this parameter to skip the reauthentication logic.
63+
const isDeprecatedRequest = !apiRequestType;
6764
const skipReauthentication = lodashGet(request, 'data.skipReauthentication');
68-
if ((!shouldRetry && !apiRequestType) || skipReauthentication) {
69-
if (isFromSequentialQueue) {
70-
return data;
71-
}
72-
65+
if (!isFromSequentialQueue && (isDeprecatedRequest || skipReauthentication)) {
7366
if (request.resolve) {
7467
request.resolve(data);
68+
return;
7569
}
7670
return data;
7771
}
7872

79-
// We are already authenticating and using the DeprecatedAPI so we will replay the request
80-
if (!apiRequestType && NetworkStore.isAuthenticating()) {
81-
MainQueue.replay(request);
82-
return data;
83-
}
84-
8573
return reauthenticate(request.commandName)
8674
.then((authenticateResponse) => {
8775
if (isFromSequentialQueue || apiRequestType === CONST.API_REQUEST_TYPE.MAKE_REQUEST_WITH_SIDE_EFFECTS) {

src/libs/Network/MainQueue.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import _ from 'underscore';
2-
import lodashGet from 'lodash/get';
32
import * as NetworkStore from './NetworkStore';
43
import * as SequentialQueue from './SequentialQueue';
54
import * as Request from '../Request';
5+
import CONST from '../../CONST';
66

77
// Queue for network requests so we don't lose actions done by the user while offline
88
let networkRequestQueue = [];
@@ -56,18 +56,12 @@ function process() {
5656
// Some requests should be retried and will end up here if the following conditions are met:
5757
// - we are in the process of authenticating and the request is retryable (most are)
5858
// - the request does not have forceNetworkRequest === true (this will trigger it to process immediately)
59-
// - the request does not have shouldRetry === false (specified when we do not want to retry, defaults to true)
6059
const requestsToProcessOnNextRun = [];
6160

6261
_.each(networkRequestQueue, (queuedRequest) => {
63-
// Check if we can make this request at all and if we can't see if we should save it for the next run or chuck it into the ether
62+
// Check if we can make this request at all and if we can't see if we should save it for the next run
6463
if (!canMakeRequest(queuedRequest)) {
65-
const shouldRetry = lodashGet(queuedRequest, 'data.shouldRetry');
66-
if (shouldRetry) {
67-
requestsToProcessOnNextRun.push(queuedRequest);
68-
} else {
69-
console.debug('Skipping request that should not be re-tried: ', {command: queuedRequest.command});
70-
}
64+
requestsToProcessOnNextRun.push(queuedRequest);
7165
return;
7266
}
7367

@@ -84,7 +78,7 @@ function process() {
8478
* Non-cancellable requests like Log would not be cleared
8579
*/
8680
function clear() {
87-
networkRequestQueue = _.filter(networkRequestQueue, (request) => !request.data.canCancel);
81+
_.filter(networkRequestQueue, (request) => request.command !== CONST.NETWORK.COMMAND.LOG);
8882
}
8983

9084
/**

src/libs/Network/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ function post(command, data = {}, type = CONST.NETWORK.METHOD.POST, shouldUseSec
3535
// (e.g. any requests currently happening when the user logs out are cancelled)
3636
request.data = {
3737
...data,
38-
shouldRetry: lodashGet(data, 'shouldRetry', true),
39-
canCancel: lodashGet(data, 'canCancel', true),
4038
appversion: pkg.version,
4139
};
4240

src/libs/actions/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ function beginDeepLinkRedirect() {
340340
}
341341

342342
// eslint-disable-next-line rulesdir/no-api-side-effects-method
343-
API.makeRequestWithSideEffects('OpenOldDotLink', {shouldRetry: false}, {}).then((response) => {
343+
API.makeRequestWithSideEffects('OpenOldDotLink', {}, {}).then((response) => {
344344
Browser.openRouteInDesktopApp(response.shortLivedAuthToken, currentUserEmail);
345345
});
346346
}

src/libs/actions/Report.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,6 @@ function openReport(reportID, participantLoginList = [], newReportObject = {}, p
424424
parentReportActionID,
425425
};
426426

427-
if (isFromDeepLink) {
428-
params.shouldRetry = false;
429-
}
430-
431427
// If we open an exist report, but it is not present in Onyx yet, we should change the method to set for this report
432428
// and we need data to be available when we navigate to the chat page
433429
if (_.isEmpty(ReportUtils.getReport(reportID))) {

src/libs/actions/Session/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ function signOut() {
7171
partnerUserID: lodashGet(credentials, 'autoGeneratedLogin', ''),
7272
partnerName: CONFIG.EXPENSIFY.PARTNER_NAME,
7373
partnerPassword: CONFIG.EXPENSIFY.PARTNER_PASSWORD,
74-
shouldRetry: false,
7574
});
7675
clearCache().then(() => {
7776
Log.info('Cleared all chache data', true, {}, true);
@@ -290,6 +289,9 @@ function signInWithShortLivedAuthToken(email, authToken) {
290289
// If the user is signing in with a different account from the current app, should not pass the auto-generated login as it may be tied to the old account.
291290
// scene 1: the user is transitioning to newDot from a different account on oldDot.
292291
// scene 2: the user is transitioning to desktop app from a different account on web app.
292+
// For the SignInWithShortLivedAuthToken command, if the short token expires, the server returns a 407 error,
293+
// and credentials are still empty at this time, which causes reauthenticate to throw an error (requireParameters),
294+
// and the subsequent SaveResponseInOnyx also cannot be executed, so we need this parameter to skip the reauthentication logic.
293295
const oldPartnerUserID = credentials.login === email ? credentials.autoGeneratedLogin : '';
294296
API.read('SignInWithShortLivedAuthToken', {authToken, oldPartnerUserID, skipReauthentication: true}, {optimisticData, successData, failureData});
295297
}
@@ -545,7 +547,6 @@ function authenticatePusher(socketID, channelName, callback) {
545547
API.makeRequestWithSideEffects('AuthenticatePusher', {
546548
socket_id: socketID,
547549
channel_name: channelName,
548-
shouldRetry: false,
549550
forceNetworkRequest: true,
550551
})
551552
.then((response) => {

0 commit comments

Comments
 (0)