Skip to content
Open
Show file tree
Hide file tree
Changes from 10 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "error surfacing changes",
"packageName": "@azure/msal-common",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "error surfacing changes",
"packageName": "@azure/msal-node-extensions",
"email": "[email protected]",
"dependentChangeType": "patch"
}
50 changes: 34 additions & 16 deletions extensions/msal-node-extensions/src/broker/NativeBrokerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
InteractionRequiredAuthError,
Logger,
LoggerOptions,
PlatformBrokerError,
NativeRequest,
NativeSignOutRequest,
PromptValue,
Expand All @@ -38,8 +39,6 @@ import {
LogLevel as MsalRuntimeLogLevel,
} from "@azure/msal-node-runtime";
import { ErrorCodes } from "../utils/Constants.js";
import { StringUtils } from "../utils/StringUtils.js";
import { NativeAuthError } from "../error/NativeAuthError.js";
import { version, name } from "../packageMetadata.js";

export class NativeBrokerPlugin implements INativeBrokerPlugin {
Expand Down Expand Up @@ -648,58 +647,77 @@ export class NativeBrokerPlugin implements INativeBrokerPlugin {
);
}

private wrapError(error: unknown): NativeAuthError | Object | null {
private wrapError(error: unknown): PlatformBrokerError | Object | null {
if (
error &&
typeof error === "object" &&
this.isMsalRuntimeError(error)
) {
const { errorCode, errorStatus, errorContext, errorTag } =
error as MsalRuntimeError;
const tagString = StringUtils.tagToString(errorTag);
const enhancedErrorContext = errorContext
? `${errorContext} (Error Code: ${errorCode}, Tag: ${tagString})`
: `(Error Code: ${errorCode}, Tag: ${tagString})`;

const msalNodeRuntimeError = new PlatformBrokerError(
ErrorStatus[errorStatus],
errorContext,
errorCode,
errorTag
);

let wrappedError;

switch (errorStatus) {
case ErrorStatus.InteractionRequired:
case ErrorStatus.AccountUnusable:
return new InteractionRequiredAuthError(
wrappedError = new InteractionRequiredAuthError(
ErrorCodes.INTERATION_REQUIRED_ERROR_CODE,
enhancedErrorContext
msalNodeRuntimeError.message
);
break;
case ErrorStatus.NoNetwork:
case ErrorStatus.NetworkTemporarilyUnavailable:
return createClientAuthError(
wrappedError = createClientAuthError(
ClientAuthErrorCodes.noNetworkConnectivity
);
break;
case ErrorStatus.ServerTemporarilyUnavailable:
return new ServerError(
wrappedError = new ServerError(
ErrorCodes.SERVER_UNAVAILABLE,
errorContext
);
break;
case ErrorStatus.UserCanceled:
return createClientAuthError(
wrappedError = createClientAuthError(
ClientAuthErrorCodes.userCanceled
);
break;
case ErrorStatus.AuthorityUntrusted:
return createClientConfigurationError(
wrappedError = createClientConfigurationError(
ClientConfigurationErrorCodes.untrustedAuthority
);
break;
case ErrorStatus.UserSwitched:
// Not an error case, if there's customer demand we can surface this as a response property
return null;
case ErrorStatus.AccountNotFound:
return createClientAuthError(
wrappedError = createClientAuthError(
ClientAuthErrorCodes.noAccountFound
);
break;
default:
return new NativeAuthError(
wrappedError = msalNodeRuntimeError;
// Clone error to avoid circular reference
const clonedError = new PlatformBrokerError(
ErrorStatus[errorStatus],
enhancedErrorContext,
errorContext,
errorCode,
errorTag
);
wrappedError.platformBrokerError = clonedError;
return wrappedError;
}

wrappedError.platformBrokerError = msalNodeRuntimeError;
return wrappedError;
}
throw error;
}
Expand Down
25 changes: 0 additions & 25 deletions extensions/msal-node-extensions/src/error/NativeAuthError.ts

This file was deleted.

1 change: 0 additions & 1 deletion extensions/msal-node-extensions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ export { CrossPlatformLockOptions } from "./lock/CrossPlatformLockOptions.js";
export { PersistenceCreator } from "./persistence/PersistenceCreator.js";
export { IPersistenceConfiguration } from "./persistence/IPersistenceConfiguration.js";
export { Environment } from "./utils/Environment.js";
export { StringUtils } from "./utils/StringUtils.js";
export { NativeBrokerPlugin } from "./broker/NativeBrokerPlugin.js";
Loading