Skip to content

Commit

Permalink
Merge pull request #10812 from DestinyItemManager/dim-sync-tokens
Browse files Browse the repository at this point in the history
Handle expired Bungie tokens better from DIM Sync
  • Loading branch information
bhollis authored Nov 27, 2024
2 parents 23ae630 + 8ee93f3 commit a19bffd
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/app/dim-api/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DeleteAllResponse } from '@destinyitemmanager/dim-api-types';
import { needsDeveloper } from 'app/accounts/actions';
import { DestinyAccount } from 'app/accounts/destiny-account';
import { accountsSelector, currentAccountSelector } from 'app/accounts/selectors';
import { FatalTokenError } from 'app/bungie-api/authenticated-fetch';
import { dimErrorToaster } from 'app/bungie-api/error-toaster';
import { getToken } from 'app/bungie-api/oauth-tokens';
import { t } from 'app/i18next-t';
Expand Down Expand Up @@ -246,6 +247,14 @@ export function loadDimApiData(forceLoad = false): ThunkResult {
// Quickly heal from being failure backoff
getProfileBackoff = Math.floor(getProfileBackoff / 2);
} catch (err) {
if (err instanceof FatalTokenError) {
// We're already sent to login, don't keep trying to use DIM Sync.
if ($DIM_FLAVOR === 'dev') {
dispatch(needsDeveloper());
}
return;
}

// Only notify error once
if (!getState().dimApi.profileLoadedError) {
showProfileLoadErrorNotification(err);
Expand All @@ -257,18 +266,13 @@ export function loadDimApiData(forceLoad = false): ThunkResult {

errorLog(TAG, 'Unable to get profile from DIM API', e);

if (e.name !== 'FatalTokenError') {
// Wait, with exponential backoff
getProfileBackoff++;
const waitTime = getBackoffWaitTime(getProfileBackoff);
infoLog(TAG, 'Waiting', waitTime, 'ms before re-attempting profile fetch');
// Wait, with exponential backoff
getProfileBackoff++;
const waitTime = getBackoffWaitTime(getProfileBackoff);
infoLog(TAG, 'Waiting', waitTime, 'ms before re-attempting profile fetch');

// Wait, then retry. We don't await this here so we don't stop the finally block from running
delay(waitTime).then(() => dispatch(loadDimApiData(forceLoad)));
} else if ($DIM_FLAVOR === 'dev') {
dispatch(needsDeveloper());
}
return;
// Wait, then retry. We don't await this here so we don't stop the finally block from running
delay(waitTime).then(() => dispatch(loadDimApiData(forceLoad)));
} finally {
// Release the app to load with whatever language was saved or the
// default. Better to have the wrong language (that fixes itself on
Expand Down

0 comments on commit a19bffd

Please sign in to comment.