Skip to content

Commit

Permalink
Handle expired Bungie tokens better from DIM Sync
Browse files Browse the repository at this point in the history
  • Loading branch information
bhollis committed Nov 25, 2024
1 parent b0a90c9 commit ddcb8c9
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 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,9 +247,12 @@ export function loadDimApiData(forceLoad = false): ThunkResult {
// Quickly heal from being failure backoff
getProfileBackoff = Math.floor(getProfileBackoff / 2);
} catch (err) {
// Only notify error once
if (!getState().dimApi.profileLoadedError) {
showProfileLoadErrorNotification(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;
}

const e = convertToError(err);
Expand All @@ -257,18 +261,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 ddcb8c9

Please sign in to comment.