Skip to content

Commit 0493ccd

Browse files
smaller diff
1 parent 623b5fc commit 0493ccd

File tree

3 files changed

+17
-25
lines changed

3 files changed

+17
-25
lines changed

src/error.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,30 +1158,14 @@ export class MongoServerSelectionError extends MongoSystemError {
11581158
}
11591159
}
11601160

1161-
/**
1162-
* The type of the result property of MongoWriteConcernError
1163-
* @public
1164-
*/
1165-
export interface WriteConcernErrorResult {
1166-
writeConcernError: {
1167-
code: number;
1168-
errmsg: string;
1169-
codeName?: string;
1170-
errInfo?: Document;
1171-
};
1172-
ok: 0 | 1;
1173-
code?: number;
1174-
[x: string | number]: unknown;
1175-
}
1176-
11771161
/**
11781162
* An error thrown when the server reports a writeConcernError
11791163
* @public
11801164
* @category Error
11811165
*/
11821166
export class MongoWriteConcernError extends MongoServerError {
11831167
/** The result document */
1184-
result: WriteConcernErrorResult;
1168+
result: Document;
11851169

11861170
/**
11871171
* **Do not use this constructor!**
@@ -1194,9 +1178,18 @@ export class MongoWriteConcernError extends MongoServerError {
11941178
*
11951179
* @public
11961180
**/
1197-
constructor(result: WriteConcernErrorResult) {
1198-
super(result);
1199-
this.errInfo = result.writeConcernError?.errInfo;
1181+
constructor(result: {
1182+
writeConcernError: {
1183+
code: number;
1184+
errmsg: string;
1185+
codeName?: string;
1186+
errInfo?: Document;
1187+
};
1188+
errorLabels?: string[];
1189+
code?: number;
1190+
}) {
1191+
super({ ...result, ...result.writeConcernError });
1192+
this.errInfo = result.writeConcernError.errInfo;
12001193
this.result = result;
12011194
this.code = result.code ? result.code : undefined;
12021195
}

test/unit/error.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ import {
3030
setDifference,
3131
type TopologyDescription,
3232
type TopologyOptions,
33-
WaitQueueTimeoutError as MongoWaitQueueTimeoutError,
34-
WriteConcernErrorResult
33+
WaitQueueTimeoutError as MongoWaitQueueTimeoutError
3534
} from '../mongodb';
3635
import { ReplSetFixture } from '../tools/common';
3736
import { cleanup } from '../tools/mongodb-mock/index';
@@ -745,7 +744,7 @@ describe('MongoErrors', () => {
745744
describe('MongoWriteConcernError constructor', function () {
746745
context('when no top-level code is provided and writeConcernError.code exists', function () {
747746
it('error.code remains undefined', function () {
748-
const res: WriteConcernErrorResult = {
747+
const res = {
749748
writeConcernError: {
750749
code: 81, // nested code
751750
errmsg: 'fake msg'
@@ -758,7 +757,7 @@ describe('MongoErrors', () => {
758757
context('when top-level code is provided and writeConcernError.code exists', function () {
759758
it('error.code equals the top-level code', function () {
760759
const topLevelCode = 10;
761-
const res: WriteConcernErrorResult = {
760+
const res = {
762761
writeConcernError: {
763762
code: 81, // nested code
764763
errmsg: 'fake msg'

test/unit/mongo_client.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ describe('MongoClient', function () {
737737
expect(error).to.have.property('code', 'EBADNAME');
738738
});
739739

740-
it.only('srvServiceName should not error if it is greater than 15 characters as long as the DNS query limit is not surpassed', async () => {
740+
it('srvServiceName should not error if it is greater than 15 characters as long as the DNS query limit is not surpassed', async () => {
741741
const options = parseOptions('mongodb+srv://localhost.a.com', {
742742
srvServiceName: 'a'.repeat(16)
743743
});

0 commit comments

Comments
 (0)