Skip to content

Commit

Permalink
expanded types to MongoError to support the diff error types
Browse files Browse the repository at this point in the history
  • Loading branch information
aditi-khare-mongoDB committed Mar 8, 2024
1 parent 2bbe020 commit 82fa338
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/sdam/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
MongoNetworkTimeoutError,
MongoRuntimeError,
MongoServerClosedError,
type MongoServerError,
MongoServerError,
needsRetryableWriteLabel
} from '../error';
import type { ServerApi } from '../mongo_client';
Expand Down Expand Up @@ -369,7 +369,7 @@ export class Server extends TypedEventEmitter<ServerEvents> {
// clear for the specific service id.
if (!this.loadBalanced) {
error.addErrorLabel(MongoErrorLabel.ResetPool);
markServerUnknown(this, error as MongoServerError);
markServerUnknown(this, error);
} else if (connection) {
this.pool.clear({ serviceId: connection.serviceId });
}
Expand All @@ -385,7 +385,7 @@ export class Server extends TypedEventEmitter<ServerEvents> {
if (shouldClearPool) {
error.addErrorLabel(MongoErrorLabel.ResetPool);
}
markServerUnknown(this, error as MongoServerError);
markServerUnknown(this, error);
process.nextTick(() => this.requestCheck());
}
}
Expand Down Expand Up @@ -488,7 +488,7 @@ function calculateRoundTripTime(oldRtt: number, duration: number): number {
return alpha * duration + (1 - alpha) * oldRtt;
}

function markServerUnknown(server: Server, error?: MongoServerError) {
function markServerUnknown(server: Server, error?: MongoError) {
// Load balancer servers can never be marked unknown.
if (server.loadBalanced) {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/sdam/server_description.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Document, Long, type ObjectId } from '../bson';
import { type MongoError, MongoRuntimeError, type MongoServerError } from '../error';
import { type MongoError, MongoRuntimeError, type MongoServerError, MongoNetworkError } from '../error';
import { arrayStrictEqual, compareObjectId, errorStrictEqual, HostAddress, now } from '../utils';
import type { ClusterTime } from './common';
import { ServerType } from './common';
Expand Down Expand Up @@ -31,7 +31,7 @@ export type TagSet = { [key: string]: string };
/** @internal */
export interface ServerDescriptionOptions {
/** An Error used for better reporting debugging */
error?: MongoServerError;
error?: MongoError;

/** The round trip time to ping this server (in ms) */
roundTripTime?: number;
Expand Down
6 changes: 3 additions & 3 deletions src/sdam/topology_description.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ObjectId } from '../bson';
import * as WIRE_CONSTANTS from '../cmap/wire_protocol/constants';
import { MongoRuntimeError, type MongoServerError } from '../error';
import { MongoError, MongoRuntimeError } from '../error';
import { compareObjectId, shuffle } from '../utils';
import { ServerType, TopologyType } from './common';
import { ServerDescription } from './server_description';
Expand Down Expand Up @@ -307,13 +307,13 @@ export class TopologyDescription {
);
}

get error(): MongoServerError | null {
get error(): MongoError | null {
const descriptionsWithError = Array.from(this.servers.values()).filter(
(sd: ServerDescription) => sd.error
);

if (descriptionsWithError.length > 0) {
return descriptionsWithError[0].error as MongoServerError;
return descriptionsWithError[0].error;
}

return null;
Expand Down

0 comments on commit 82fa338

Please sign in to comment.