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

fix(oidc): improve error handling (release) #1403

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/oidc-client/src/oidc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,12 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
return await fetchFromIssuer(this.getFetch())(authority, this.configuration.authority_time_cache_wellknowurl_in_second ?? 60 * 60, storage, this.configuration.authority_timeout_wellknowurl_in_millisecond);
};
this.initPromise = localFuncAsync();
return this.initPromise.then((result) => {
return this.initPromise.finally(() => {
// in case if anything went wrong with the promise, we should reset the initPromise to null too
// otherwise client can't re-init the OIDC client
// as the promise is already fulfilled with rejected state, so could not ever reach this point again,
// so that leads to infinite loop of calls, when client tries to re-init the OIDC client after error
this.initPromise = null;
return result;
});
}

Expand Down
16 changes: 14 additions & 2 deletions packages/oidc-client/src/renewTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,19 @@ const synchroniseTokensAsync = (oidc:Oidc) => async (index = 0, forceRefresh = f
}
} catch (exception: any) {
console.error(exception);
oidc.publishEvent(eventNames.refreshTokensAsync_silent_error, { message: 'exception', exception: exception.message });
return synchroniseTokensAsync(oidc)(nextIndex, forceRefresh, extras, updateTokens);
oidc.publishEvent(eventNames.refreshTokensAsync_silent_error, {
message: 'exception',
exception: exception.message,
});
// we need to break the loop or errors, as direct call of synchroniseTokensAsync
// inside of synchroniseTokensAsync will cause an infinite loop and kill the browser stack
// so we need to brake calls chain and delay next call
return new Promise((resolve, reject) => {
setTimeout(() => {
synchroniseTokensAsync(oidc)(nextIndex, forceRefresh, extras, updateTokens)
.then(resolve)
.catch(reject);
}, 1000);
});
}
}
Loading