Skip to content

Commit a881842

Browse files
- Move auth error messages out of the bundle
1 parent 24f3394 commit a881842

16 files changed

Lines changed: 394 additions & 383 deletions

lib/msal-browser/docs/errors.md

Lines changed: 157 additions & 74 deletions
Large diffs are not rendered by default.

lib/msal-browser/src/error/BrowserAuthError.ts

Lines changed: 1 addition & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -7,107 +7,12 @@ import { AuthError } from "@azure/msal-common/browser";
77
import * as BrowserAuthErrorCodes from "./BrowserAuthErrorCodes.js";
88
export { BrowserAuthErrorCodes }; // Allow importing as "BrowserAuthErrorCodes"
99

10-
const ErrorLink = "For more visit: aka.ms/msaljs/browser-errors";
11-
12-
/**
13-
* BrowserAuthErrorMessage class containing string constants used by error codes and messages.
14-
*/
15-
export const BrowserAuthErrorMessages = {
16-
[BrowserAuthErrorCodes.pkceNotCreated]:
17-
"The PKCE code challenge and verifier could not be generated.",
18-
[BrowserAuthErrorCodes.earJwkEmpty]:
19-
"No EAR encryption key provided. This is unexpected.",
20-
[BrowserAuthErrorCodes.earJweEmpty]:
21-
"Server response does not contain ear_jwe property. This is unexpected.",
22-
[BrowserAuthErrorCodes.cryptoNonExistent]:
23-
"The crypto object or function is not available.",
24-
[BrowserAuthErrorCodes.emptyNavigateUri]:
25-
"Navigation URI is empty. Please check stack trace for more info.",
26-
[BrowserAuthErrorCodes.hashEmptyError]: `Hash value cannot be processed because it is empty. Please verify that your redirectUri is not clearing the hash. ${ErrorLink}`,
27-
[BrowserAuthErrorCodes.noStateInHash]:
28-
"Hash does not contain state. Please verify that the request originated from msal.",
29-
[BrowserAuthErrorCodes.hashDoesNotContainKnownProperties]: `Hash does not contain known properites. Please verify that your redirectUri is not changing the hash. ${ErrorLink}`,
30-
[BrowserAuthErrorCodes.unableToParseState]:
31-
"Unable to parse state. Please verify that the request originated from msal.",
32-
[BrowserAuthErrorCodes.stateInteractionTypeMismatch]:
33-
"Hash contains state but the interaction type does not match the caller.",
34-
[BrowserAuthErrorCodes.interactionInProgress]: `Interaction is currently in progress. Please ensure that this interaction has been completed before calling an interactive API. ${ErrorLink}`,
35-
[BrowserAuthErrorCodes.popupWindowError]:
36-
"Error opening popup window. This can happen if you are using IE or if popups are blocked in the browser.",
37-
[BrowserAuthErrorCodes.emptyWindowError]:
38-
"window.open returned null or undefined window object.",
39-
[BrowserAuthErrorCodes.userCancelled]: "User cancelled the flow.",
40-
[BrowserAuthErrorCodes.monitorPopupTimeout]: `Token acquisition in popup failed due to timeout. ${ErrorLink}`,
41-
[BrowserAuthErrorCodes.monitorWindowTimeout]: `Token acquisition in iframe failed due to timeout. ${ErrorLink}`,
42-
[BrowserAuthErrorCodes.redirectInIframe]:
43-
"Redirects are not supported for iframed or brokered applications. Please ensure you are using MSAL.js in a top frame of the window if using the redirect APIs, or use the popup APIs.",
44-
[BrowserAuthErrorCodes.blockIframeReload]: `Request was blocked inside an iframe because MSAL detected an authentication response. ${ErrorLink}`,
45-
[BrowserAuthErrorCodes.blockNestedPopups]:
46-
"Request was blocked inside a popup because MSAL detected it was running in a popup.",
47-
[BrowserAuthErrorCodes.iframeClosedPrematurely]:
48-
"The iframe being monitored was closed prematurely.",
49-
[BrowserAuthErrorCodes.silentLogoutUnsupported]:
50-
"Silent logout not supported. Please call logoutRedirect or logoutPopup instead.",
51-
[BrowserAuthErrorCodes.noAccountError]:
52-
"No account object provided to acquireTokenSilent and no active account has been set. Please call setActiveAccount or provide an account on the request.",
53-
[BrowserAuthErrorCodes.silentPromptValueError]:
54-
"The value given for the prompt value is not valid for silent requests - must be set to 'none' or 'no_session'.",
55-
[BrowserAuthErrorCodes.noTokenRequestCacheError]:
56-
"No token request found in cache.",
57-
[BrowserAuthErrorCodes.unableToParseTokenRequestCacheError]:
58-
"The cached token request could not be parsed.",
59-
[BrowserAuthErrorCodes.authRequestNotSetError]:
60-
"Auth Request not set. Please ensure initiateAuthRequest was called from the InteractionHandler",
61-
[BrowserAuthErrorCodes.invalidCacheType]: "Invalid cache type",
62-
[BrowserAuthErrorCodes.nonBrowserEnvironment]:
63-
"Login and token requests are not supported in non-browser environments.",
64-
[BrowserAuthErrorCodes.databaseNotOpen]: "Database is not open!",
65-
[BrowserAuthErrorCodes.noNetworkConnectivity]:
66-
"No network connectivity. Check your internet connection.",
67-
[BrowserAuthErrorCodes.postRequestFailed]:
68-
"Network request failed: If the browser threw a CORS error, check that the redirectUri is registered in the Azure App Portal as type 'SPA'",
69-
[BrowserAuthErrorCodes.getRequestFailed]:
70-
"Network request failed. Please check the network trace to determine root cause.",
71-
[BrowserAuthErrorCodes.failedToParseResponse]:
72-
"Failed to parse network response. Check network trace.",
73-
[BrowserAuthErrorCodes.unableToLoadToken]: "Error loading token to cache.",
74-
[BrowserAuthErrorCodes.cryptoKeyNotFound]:
75-
"Cryptographic Key or Keypair not found in browser storage.",
76-
[BrowserAuthErrorCodes.authCodeRequired]:
77-
"An authorization code must be provided (as the `code` property on the request) to this flow.",
78-
[BrowserAuthErrorCodes.authCodeOrNativeAccountIdRequired]:
79-
"An authorization code or nativeAccountId must be provided to this flow.",
80-
[BrowserAuthErrorCodes.spaCodeAndNativeAccountIdPresent]:
81-
"Request cannot contain both spa code and native account id.",
82-
[BrowserAuthErrorCodes.databaseUnavailable]:
83-
"IndexedDB, which is required for persistent cryptographic key storage, is unavailable. This may be caused by browser privacy features which block persistent storage in third-party contexts.",
84-
[BrowserAuthErrorCodes.unableToAcquireTokenFromNativePlatform]: `Unable to acquire token from native platform. ${ErrorLink}`,
85-
[BrowserAuthErrorCodes.nativeHandshakeTimeout]:
86-
"Timed out while attempting to establish connection to browser extension",
87-
[BrowserAuthErrorCodes.nativeExtensionNotInstalled]:
88-
"Native extension is not installed. If you think this is a mistake call the initialize function.",
89-
[BrowserAuthErrorCodes.nativeConnectionNotEstablished]: `Connection to native platform has not been established. Please install a compatible browser extension and run initialize(). ${ErrorLink}`,
90-
[BrowserAuthErrorCodes.uninitializedPublicClientApplication]: `You must call and await the initialize function before attempting to call any other MSAL API. ${ErrorLink}`,
91-
[BrowserAuthErrorCodes.nativePromptNotSupported]:
92-
"The provided prompt is not supported by the native platform. This request should be routed to the web based flow.",
93-
[BrowserAuthErrorCodes.invalidBase64String]:
94-
"Invalid base64 encoded string.",
95-
[BrowserAuthErrorCodes.invalidPopTokenRequest]:
96-
"Invalid PoP token request. The request should not have both a popKid value and signPopToken set to true.",
97-
[BrowserAuthErrorCodes.failedToBuildHeaders]:
98-
"Failed to build request headers object.",
99-
[BrowserAuthErrorCodes.failedToParseHeaders]:
100-
"Failed to parse response headers",
101-
[BrowserAuthErrorCodes.failedToDecryptEarResponse]:
102-
"Failed to decrypt ear response",
103-
};
104-
10510
/**
10611
* Browser library error class thrown by the MSAL.js library for SPAs
10712
*/
10813
export class BrowserAuthError extends AuthError {
10914
constructor(errorCode: string, subError?: string) {
110-
super(errorCode, BrowserAuthErrorMessages[errorCode], subError);
15+
super(errorCode, `See https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/errors.md#${errorCode} for details`, subError);
11116

11217
Object.setPrototypeOf(this, BrowserAuthError.prototype);
11318
this.name = "BrowserAuthError";

lib/msal-browser/src/error/BrowserConfigurationAuthError.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@
66
import { AuthError } from "@azure/msal-common/browser";
77
import * as BrowserConfigurationAuthErrorCodes from "./BrowserConfigurationAuthErrorCodes.js";
88
export { BrowserConfigurationAuthErrorCodes };
9-
10-
export const BrowserConfigurationAuthErrorMessages = {
11-
[BrowserConfigurationAuthErrorCodes.storageNotSupported]:
12-
"Given storage configuration option was not supported.",
13-
[BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled]:
14-
"Stub instance of Public Client Application was called. If using msal-react, please ensure context is not used without a provider. For more visit: aka.ms/msaljs/browser-errors",
15-
[BrowserConfigurationAuthErrorCodes.inMemRedirectUnavailable]:
16-
"Redirect cannot be supported. In-memory storage was selected and storeAuthStateInCookie=false, which would cause the library to be unable to handle the incoming hash. If you would like to use the redirect API, please use session/localStorage or set storeAuthStateInCookie=true.",
17-
};
18-
199
/**
2010
* Browser library error class thrown by the MSAL.js library for SPAs
2111
*/
@@ -32,7 +22,6 @@ export function createBrowserConfigurationAuthError(
3222
errorCode: string
3323
): BrowserConfigurationAuthError {
3424
return new BrowserConfigurationAuthError(
35-
errorCode,
36-
BrowserConfigurationAuthErrorMessages[errorCode]
25+
errorCode
3726
);
3827
}

lib/msal-browser/src/error/NativeAuthError.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ export type OSError = {
2828

2929
const INVALID_METHOD_ERROR = -2147186943;
3030

31-
export const NativeAuthErrorMessages = {
32-
[NativeAuthErrorCodes.userSwitch]:
33-
"User attempted to switch accounts in the native broker, which is not allowed. All new accounts must sign-in through the standard web flow first, please try again.",
34-
};
35-
3631
export class NativeAuthError extends AuthError {
3732
ext: OSError | undefined;
3833

@@ -107,7 +102,7 @@ export function createNativeAuthError(
107102

108103
return new NativeAuthError(
109104
code,
110-
NativeAuthErrorMessages[code] || description,
105+
description,
111106
ext
112107
);
113108
}

lib/msal-browser/src/error/NativeAuthErrorCodes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55

66
export const contentError = "ContentError";
77
export const userSwitch = "user_switch";
8+
export const unsupportedMethod = "unsupported_method";

lib/msal-browser/src/error/NestedAppAuthError.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,7 @@
44
*/
55

66
import { AuthError } from "@azure/msal-common/browser";
7-
8-
/**
9-
* NestedAppAuthErrorMessage class containing string constants used by error codes and messages.
10-
*/
11-
export const NestedAppAuthErrorMessage = {
12-
unsupportedMethod: {
13-
code: "unsupported_method",
14-
desc: "This method is not supported in nested app environment.",
15-
},
16-
};
7+
import { unsupportedMethod } from "./NativeAuthErrorCodes.js";
178

189
export class NestedAppAuthError extends AuthError {
1910
constructor(errorCode: string, errorMessage?: string) {
@@ -25,8 +16,7 @@ export class NestedAppAuthError extends AuthError {
2516

2617
public static createUnsupportedError(): NestedAppAuthError {
2718
return new NestedAppAuthError(
28-
NestedAppAuthErrorMessage.unsupportedMethod.code,
29-
NestedAppAuthErrorMessage.unsupportedMethod.desc
19+
unsupportedMethod
3020
);
3121
}
3222
}

lib/msal-browser/src/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,10 @@ export {
110110
// Error
111111
AuthError,
112112
AuthErrorCodes,
113-
AuthErrorMessages,
114113
ClientAuthError,
115114
ClientAuthErrorCodes,
116-
ClientAuthErrorMessages,
117115
ClientConfigurationError,
118116
ClientConfigurationErrorCodes,
119-
ClientConfigurationErrorMessages,
120117
InteractionRequiredAuthError,
121118
InteractionRequiredAuthErrorCodes,
122119
ServerError,

0 commit comments

Comments
 (0)