Skip to content

Commit 43ab9b0

Browse files
committed
Use assertMongoError.
1 parent 325828f commit 43ab9b0

File tree

2 files changed

+8
-64
lines changed

2 files changed

+8
-64
lines changed

lib/exceptions.js

Lines changed: 6 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,17 @@
11
/*!
22
* Copyright (c) 2012-2022 Digital Bazaar, Inc. All rights reserved.
33
*/
4+
5+
import {MongoError} from 'mongodb';
6+
47
// Mongo DB Errors
58
// Errors outside of the Mongo class of Errors
69
export const WRITE_CONCERN_ERROR = 'WriteConcernError';
710
export const WRITE_ERROR = 'WriteError';
8-
9-
export const MDBE_API_ERROR = 'MongoAPIError';
10-
export const MDBE_AWS_ERROR = 'MongoAWSError';
11-
export const MDBE_BATCH_REEXECUTION_ERROR = 'MongoBatchReExecutionError';
12-
export const MDBE_BULK_WRITE_ERROR = 'MongoBulkWriteError';
13-
export const MDBE_CHANGE_STREAM_ERROR = 'MongoChangeStreamError';
14-
export const MDBE_COMPATIBILITY_ERROR = 'MongoCompatibilityError';
15-
export const MDBE_CURSOR_EXHAUSTED_ERROR = 'MongoCursorExhaustedError';
16-
export const MDBE_CURSOR_IN_USE_ERROR = 'MongoCursorInUseError';
17-
export const MDBE_DECOMPRESSION_ERROR = 'MongoDecompressionError';
18-
export const MDBE_EXPIRED_SESSION_ERROR = 'MongoExpiredSessionError';
19-
export const MDBE_GRID_FS_CHUNK_ERROR = 'MongoGridFSChunkError';
20-
export const MDBE_GRID_FS_STREAM_ERROR = 'MongoGridFSStreamError';
21-
export const MDBE_INVALID_ARGUMENT_ERROR = 'MongoInvalidArgumentError';
22-
export const MDBE_MISSING_CREDENTIALS_ERROR = 'MongoMissingCredentialsError';
23-
export const MDBE_MISSING_DEPENDENCY_ERROR = 'MongoMissingDependencyError';
24-
export const MDBE_NETWORK_ERROR = 'MongoNetworkError';
25-
export const MDBE_NETWORK_TIMEOUT_ERROR = 'MongoNetworkTimeoutError';
26-
export const MDBE_NOT_CONNECTED_ERROR = 'MongoNotConnectedError';
27-
export const MDBE_PARSE_ERROR = 'MongoParseError';
28-
export const MDBE_RUNTIME_ERROR = 'MongoRunTimeError';
29-
export const MDBE_SERVER_CLOSED_ERROR = 'MongoServerClosedError';
30-
export const MDBE_SERVER_SELECTION_ERROR = 'MongoServerSelectionError';
31-
export const MDBE_TAILABLE_CURSOR_ERROR = 'MongoTailableCursorError';
32-
export const MDBE_TOPOLOGY_CLOSED_ERROR = 'MongoTopologyClosedError';
33-
export const MDBE_TRANSACTION_ERROR = 'MongoTransactionError';
34-
export const MDBE_UNEXPECTED_SERVER_RESPONSE_ERROR =
35-
'MongoUnexpectedServerResponseError';
36-
export const MDBE_SERVER_ERROR = 'MongoServerError';
3711
export const MDBE_WRITE_CONCERN_ERROR = 'MongoWriteConcernError';
38-
// Set of all MDBE related errors
39-
export const MDBE_ERRORS = new Set([
40-
MDBE_API_ERROR,
41-
MDBE_AWS_ERROR,
42-
MDBE_BATCH_REEXECUTION_ERROR,
43-
MDBE_BULK_WRITE_ERROR,
44-
MDBE_CHANGE_STREAM_ERROR,
45-
MDBE_COMPATIBILITY_ERROR,
46-
MDBE_CURSOR_EXHAUSTED_ERROR,
47-
MDBE_CURSOR_IN_USE_ERROR,
48-
MDBE_DECOMPRESSION_ERROR,
49-
MDBE_EXPIRED_SESSION_ERROR,
50-
MDBE_GRID_FS_CHUNK_ERROR,
51-
MDBE_GRID_FS_STREAM_ERROR,
52-
MDBE_INVALID_ARGUMENT_ERROR,
53-
MDBE_MISSING_CREDENTIALS_ERROR,
54-
MDBE_MISSING_DEPENDENCY_ERROR,
55-
MDBE_NETWORK_ERROR,
56-
MDBE_NETWORK_TIMEOUT_ERROR,
57-
MDBE_NOT_CONNECTED_ERROR,
58-
MDBE_PARSE_ERROR,
59-
MDBE_RUNTIME_ERROR,
60-
MDBE_SERVER_CLOSED_ERROR,
61-
MDBE_SERVER_SELECTION_ERROR,
62-
MDBE_TAILABLE_CURSOR_ERROR,
63-
MDBE_TOPOLOGY_CLOSED_ERROR,
64-
MDBE_TRANSACTION_ERROR,
65-
MDBE_UNEXPECTED_SERVER_RESPONSE_ERROR,
66-
MDBE_SERVER_ERROR,
67-
MDBE_WRITE_CONCERN_ERROR,
68-
WRITE_CONCERN_ERROR,
69-
WRITE_ERROR
70-
]);
12+
13+
export const assertMongoError = error => error instanceof MongoError;
14+
7115
export const MDBE_AUTHN_FAILED = 18;
7216
export const MDBE_AUTHZ_FAILED = 13;
7317
export const MDBE_DUPLICATE = 11000;

lib/helpers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import * as bedrock from '@bedrock/core';
55
import crypto from 'node:crypto';
66
import {
7+
assertMongoError,
78
MDBE_AUTHN_FAILED,
8-
MDBE_ERRORS,
99
MDBE_DUPLICATE,
1010
MDBE_DUPLICATE_ON_UPDATE
1111
} from './exceptions.js';
@@ -227,7 +227,7 @@ export function isDuplicateError(err) {
227227
* not.
228228
*/
229229
export function isDatabaseError(err) {
230-
return (err && MDBE_ERRORS.has(err.name));
230+
return (err && assertMongoError(err));
231231
}
232232

233233
/**

0 commit comments

Comments
 (0)