Flatten connection login error handling

This commit is contained in:
Asier Isayas
2026-08-28 14:09:02 -07:00
parent 237391734c
commit b202bf9b7c
@@ -58,18 +58,20 @@ export const ConnectExplorer: React.FunctionComponent<Props> = ({
setIsConnecting(true); setIsConnecting(true);
try { try {
try { if (await isAccountRestrictedForConnectionStringLogin(connectionString)) {
if (await isAccountRestrictedForConnectionStringLogin(connectionString)) { setErrorMessage(
setErrorMessage( "This account has been blocked from connection-string login. Please go to cosmos.azure.com/aad for AAD based login.",
"This account has been blocked from connection-string login. Please go to cosmos.azure.com/aad for AAD based login.", );
); setIsConnecting(false);
return;
}
} catch (error) {
setErrorMessage(getErrorMessage(error as Error));
return; return;
} }
} catch (error) {
setErrorMessage(getErrorMessage(error as Error));
setIsConnecting(false);
return;
}
try {
if (isResourceTokenConnectionString(connectionString)) { if (isResourceTokenConnectionString(connectionString)) {
setAuthType(AuthType.ResourceToken); setAuthType(AuthType.ResourceToken);
return; return;
@@ -90,23 +92,21 @@ export const ConnectExplorer: React.FunctionComponent<Props> = ({
} }
// Mongo and Cassandra go through the Portal Backend // Mongo and Cassandra go through the Portal Backend
try { const encryptedToken = await fetchEncryptedToken(connectionString);
const encryptedToken = await fetchEncryptedToken(connectionString); setEncryptedToken(encryptedToken);
setEncryptedToken(encryptedToken); setAuthType(AuthType.ConnectionString);
setAuthType(AuthType.ConnectionString); } catch (error) {
} catch (error) { const errorDetails = await (error as Response).text();
const errorDetails = await (error as Response).text();
setErrorMessage( setErrorMessage(
errorDetails errorDetails
? `Couldn't authenticate with Cosmos DB: ${errorDetails}` ? `Couldn't authenticate with Cosmos DB: ${errorDetails}`
: "Failed to connect to the account. Please check the connection string and try again.", : "Failed to connect to the account. Please check the connection string and try again.",
); );
// A Forbidden usually means the account firewall dropped the request. The connection // A Forbidden usually means the account firewall dropped the request. The connection
// string is exchanged by the Portal Backend rather than the browser, so the account has // string is exchanged by the Portal Backend rather than the browser, so the account has
// to allowlist those services. // to allowlist those services.
setIsBlockedByFirewall((error as Response).status === HttpStatusCodes.Forbidden); setIsBlockedByFirewall((error as Response).status === HttpStatusCodes.Forbidden);
}
} finally { } finally {
setIsConnecting(false); setIsConnecting(false);
} }