Skip to content

Conversation

@Ugonnaak1
Copy link
Contributor

Aimed to solve the problem discussed here:
Solution 5 implementation

@Ugonnaak1 Ugonnaak1 requested a review from a team as a code owner October 30, 2025 04:04
Copilot AI review requested due to automatic review settings October 30, 2025 04:04
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances error handling for MSAL Runtime (native broker) errors by introducing a new NativeAuthError class and attaching it to wrapped MSAL.js errors. The key purpose is to preserve detailed broker error information (status code, tag) when native broker errors are converted to standard MSAL errors.

Key changes:

  • Introduces NativeAuthError class in msal-common to preserve broker-specific error details (status code and tag)
  • Adds msalNodeRuntimeError property to AuthError base class to hold the original native error
  • Modifies error wrapping logic in NativeBrokerPlugin to attach NativeAuthError instances to all wrapped errors

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/msal-common/src/exports-common.ts Exports the new NativeAuthError class from msal-common package
lib/msal-common/src/error/NativeAuthError.ts Defines new error class that extends AuthError with broker-specific properties (statusCode, tag)
lib/msal-common/src/error/AuthError.ts Adds optional msalNodeRuntimeError property to store the original native broker error
extensions/msal-node-extensions/src/broker/NativeBrokerPlugin.ts Refactors error wrapping to create NativeAuthError once and attach it to all wrapped errors via msalNodeRuntimeError property
extensions/msal-node-extensions/test/broker/NativeBrokerPlugin.spec.ts Adds test to verify msalNodeRuntimeError is properly attached to wrapped errors

/**
* Default NativeAuthError from MsalNodeRuntime when broker is enabled
*/
msalNodeRuntimeError?: NativeAuthError;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make sure this is general enough to encompass our browser scenarios as well

Suggested change
msalNodeRuntimeError?: NativeAuthError;
platformBrokerError?: PlatformBrokerError;

/**
* Error class for MSAL Runtime errors that preserves detailed broker information
*/
export class NativeAuthError extends AuthError {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename this to PlatformBrokerError as we've had a bit of a naming conflict with the CIAM team for Native Auth

*/

export class StringUtils {
export class NativeBrokerStringUtils {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's include this function in the PlatformBrokerError file as a standalone function rather than a static function on a class.

return new NativeAuthError(
wrappedError = nativeAuthError;
// Clone error to avoid circular reference
const clonedError = new NativeAuthError(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than wrapping a broker error inside a broker error let's use a ClientAuthError here as the outer error and you can give it a code of either "unknown" or "broker_error"

Comment on lines +659 to 662
const tagString = NativeBrokerStringUtils.tagToString(errorTag);
const enhancedErrorContext = errorContext
? `${errorContext} (Error Code: ${errorCode}, Tag: ${tagString})`
: `(Error Code: ${errorCode}, Tag: ${tagString})`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do this stuff in the PlatformBrokerError constructor instead? Then you don't need to export the Util function at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants