update(mongodb): MongoError hasErrorLabel missing from 3.5 (#42844)

This is minor change:
- add missing `hasErrroLabel` method to the MongoError
- mark `create` static method as deprecated
- updates JSDoc for error classes to use 3.5 version

Thanks!
This commit is contained in:
Andrew Casey
2020-03-05 10:59:11 -08:00
committed by GitHub
parent 625f5b5df2
commit bf3b94190d
2 changed files with 23 additions and 5 deletions

View File

@@ -225,10 +225,20 @@ export interface MongoCallback<T> {
export type WithTransactionCallback<T> = (session: ClientSession) => Promise<T>;
/** http://mongodb.github.io/node-mongodb-native/3.1/api/MongoError.html */
/**
* Creates a new MongoError
* see {@link http://mongodb.github.io/node-mongodb-native/3.5/api/MongoError.html}
*/
export class MongoError extends Error {
constructor(message: string);
static create(options: object): MongoError;
/**
* @deprecated
*/
static create(options: string): MongoError;
/**
* Checks the error to see if it has an error label
*/
hasErrorLabel(label: string): boolean;
code?: number;
/**
* While not documented, the 'errmsg' prop is AFAIK the only way to find out
@@ -252,14 +262,20 @@ export class MongoError extends Error {
}
/** http://mongodb.github.io/node-mongodb-native/3.1/api/MongoNetworkError.html */
/**
* An error indicating an issue with the network, including TCP errors and timeouts
* see {@link https://mongodb.github.io/node-mongodb-native/3.5/api/MongoNetworkError.html}
*/
export class MongoNetworkError extends MongoError {
constructor(message: string);
errorLabels: string[];
}
/** http://mongodb.github.io/node-mongodb-native/3.1/api/MongoParseError.html */
/**
* An error used when attempting to parse a value (like a connection string)
* see {@link https://mongodb.github.io/node-mongodb-native/3.5/api/MongoParseError.html}
*/
export class MongoParseError extends MongoError {
constructor(message: string);
}

View File

@@ -58,7 +58,9 @@ async function testFunc(): Promise<mongodb.MongoClient> {
mongodb.connect(
connectionString,
(err: mongodb.MongoError, client: mongodb.MongoClient) => {},
(err: mongodb.MongoError, client: mongodb.MongoClient) => {
err.hasErrorLabel('label'); // $ExpectType boolean
},
);
mongodb.connect(
connectionString,