Skip to content

Commit da872b4

Browse files
committed
chore: allow having the atlas cluster info independently of the connection state
We used to support only having it when connected, but it might be useful also when errored
1 parent 1122e09 commit da872b4

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/common/connectionManager.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ export type ConnectionStringAuthType = "scram" | "ldap" | "kerberos" | OIDCConne
2626
export interface ConnectionState {
2727
tag: ConnectionTag;
2828
connectionStringAuthType?: ConnectionStringAuthType;
29+
connectedAtlasCluster?: AtlasClusterConnectionInfo;
2930
}
3031

3132
export interface ConnectionStateConnected extends ConnectionState {
3233
tag: "connected";
3334
serviceProvider: NodeDriverServiceProvider;
34-
connectedAtlasCluster?: AtlasClusterConnectionInfo;
3535
}
3636

3737
export interface ConnectionStateConnecting extends ConnectionState {
@@ -104,7 +104,11 @@ export class ConnectionManager extends EventEmitter<ConnectionManagerEvents> {
104104
});
105105
} catch (error: unknown) {
106106
const errorReason = error instanceof Error ? error.message : `${error as string}`;
107-
this.changeState("connection-errored", { tag: "errored", errorReason });
107+
this.changeState("connection-errored", {
108+
tag: "errored",
109+
errorReason,
110+
connectedAtlasCluster: settings.atlas,
111+
});
108112
throw new MongoDBError(ErrorCodes.MisconfiguredConnectionString, errorReason);
109113
}
110114

@@ -119,7 +123,11 @@ export class ConnectionManager extends EventEmitter<ConnectionManagerEvents> {
119123
});
120124
} catch (error: unknown) {
121125
const errorReason = error instanceof Error ? error.message : `${error as string}`;
122-
this.changeState("connection-errored", { tag: "errored", errorReason });
126+
this.changeState("connection-errored", {
127+
tag: "errored",
128+
errorReason,
129+
connectedAtlasCluster: settings.atlas,
130+
});
123131
throw new MongoDBError(ErrorCodes.NotConnectedToMongoDB, errorReason);
124132
}
125133
}

src/common/session.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,6 @@ export class Session extends EventEmitter<SessionEvents> {
125125
}
126126

127127
get connectedAtlasCluster(): AtlasClusterConnectionInfo | undefined {
128-
const connectionState = this.connectionManager.currentConnectionState;
129-
if (connectionState.tag === "connected") {
130-
return connectionState.connectedAtlasCluster;
131-
}
132-
133-
return undefined;
128+
return this.connectionManager.currentConnectionState.connectedAtlasCluster;
134129
}
135130
}

0 commit comments

Comments
 (0)