@@ -125,7 +125,12 @@ function isAggregateError(e: unknown): e is Error & { errors: Error[] } {
125125 * mongodb-client-encryption has a dependency on this error, it uses the constructor with a string argument
126126 */
127127export class MongoError extends Error {
128- public readonly errorLabels : string [ ] = [ ] ;
128+ /** @internal */
129+ private readonly errorLabelSet : Set < string > = new Set ( ) ;
130+ public get errorLabels ( ) : string [ ] {
131+ return Array . from ( this . errorLabelSet ) ;
132+ }
133+
129134 /**
130135 * This is a number in MongoServerError and a string in MongoDriverError
131136 * @privateRemarks
@@ -183,11 +188,11 @@ export class MongoError extends Error {
183188 * @returns returns true if the error has the provided error label
184189 */
185190 hasErrorLabel ( label : string ) : boolean {
186- return this . errorLabels . includes ( label ) ;
191+ return this . errorLabelSet . has ( label ) ;
187192 }
188193
189194 addErrorLabel ( label : string ) : void {
190- if ( ! this . hasErrorLabel ( label ) ) this . errorLabels . push ( label ) ;
195+ this . errorLabelSet . add ( label ) ;
191196 }
192197}
193198
@@ -1034,7 +1039,7 @@ export interface MongoNetworkErrorOptions {
10341039 */
10351040export class MongoNetworkError extends MongoError {
10361041 /** @internal */
1037- private beforeHandshake ? : boolean ;
1042+ public readonly beforeHandshake : boolean ;
10381043
10391044 /**
10401045 * **Do not use this constructor!**
@@ -1049,20 +1054,12 @@ export class MongoNetworkError extends MongoError {
10491054 **/
10501055 constructor ( message : string , options ?: MongoNetworkErrorOptions ) {
10511056 super ( message , { cause : options ?. cause } ) ;
1052-
1053- if ( options && typeof options . beforeHandshake === 'boolean' ) {
1054- this . beforeHandshake = options . beforeHandshake ;
1055- }
1057+ this . beforeHandshake = ! ! options ?. beforeHandshake ;
10561058 }
10571059
10581060 override get name ( ) : string {
10591061 return 'MongoNetworkError' ;
10601062 }
1061-
1062- /** @internal */
1063- static isBeforeHandshake ( err : MongoNetworkError ) : boolean {
1064- return err . beforeHandshake === true ;
1065- }
10661063}
10671064
10681065/**
0 commit comments