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

[Identity] Getting rid of instanceof #14763

Merged
merged 4 commits into from
Apr 7, 2021
Merged
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
20 changes: 13 additions & 7 deletions sdk/identity/identity/src/msal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,27 +149,33 @@ export class MsalBaseUtilities {
* Handles MSAL errors.
*/
protected handleError(scopes: string[], error: Error, getTokenOptions?: GetTokenOptions): Error {
if (error instanceof msalCommon.AuthError) {
switch (error.errorCode) {
if (
error.name === "AuthError" ||
error.name === "ClientAuthError" ||
error.name === "BrowserAuthError"
) {
const msalError = error as msalCommon.AuthError;
switch (msalError.errorCode) {
case "endpoints_resolution_error":
this.logger.info(formatError(scopes, error.message));
return new CredentialUnavailable(error.message);
case "consent_required":
case "interaction_required":
case "login_required":
this.logger.info(
formatError(scopes, `Authentication returned errorCode ${error.errorCode}`)
formatError(scopes, `Authentication returned errorCode ${msalError.errorCode}`)
);
break;
default:
this.logger.info(formatError(scopes, `Failed to acquire token: ${error.message}`));
break;
}
}
if (error instanceof msalCommon.ClientConfigurationError) {
return error;
}
if (error.name === "AbortError") {
if (
error.name === "ClientConfigurationError" ||
error.name === "BrowserConfigurationAuthError" ||
error.name === "AbortError"
) {
return error;
}
return new AuthenticationRequired(scopes, getTokenOptions, error.message);
Expand Down