Skip to content

Commit

Permalink
[Identity] Getting rid of instanceof (Azure#14763)
Browse files Browse the repository at this point in the history
* [Identity] Getting rid of instanceof

I had some isntances of `instanceof`, which is causing issues once @azure/msal-common gets updated, since @azure/msal-node hasn't been released with the latest version of @azure/msal-common.

I know that checking for `names` is the way to go, but I had forgotten to remove these before.

This will fix `rush update --full`.

* Update CHANGELOG.md

* CHANGELOG feedback

* more MSAL errors
  • Loading branch information
sadasant authored Apr 7, 2021
1 parent f9424f5 commit aeb7573
Showing 1 changed file with 13 additions and 7 deletions.
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 CredentialUnavailableError(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 AuthenticationRequiredError(scopes, getTokenOptions, error.message);
Expand Down

0 comments on commit aeb7573

Please sign in to comment.