Skip to content

Commit

Permalink
Basic implementation done, need to UTR changes + sync spec tests still
Browse files Browse the repository at this point in the history
  • Loading branch information
aditi-khare-mongoDB committed Mar 4, 2024
1 parent eab8f23 commit 5f87446
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export class MongoError extends Error {
* @category Error
*/
export class MongoServerError extends MongoError {
errorResponse?: ErrorDescription;
codeName?: string;
writeConcernError?: Document;
errInfo?: Document;
Expand All @@ -223,9 +224,17 @@ export class MongoServerError extends MongoError {
this[kErrorLabels] = new Set(message.errorLabels);
}

this.errorResponse = message;

for (const name in message) {
if (name !== 'errorLabels' && name !== 'errmsg' && name !== 'message')
if (
name !== 'errorLabels' &&
name !== 'errmsg' &&
name !== 'message' &&
name !== 'errorResponse'
) {
this[name] = message[name];
}
}
}

Expand Down
18 changes: 18 additions & 0 deletions test/unit/error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,24 @@ describe('MongoErrors', () => {
expect(err.message).to.equal(errorMessage);
expect(err.someData).to.equal(12345);
});
context('errorResponse property', function () {
it(`should set errorResponse to raw results document passed in`, function () {
const errorDoc = { message: 'A test error', someData: 12345 };
const err = new MongoServerError(errorDoc);
expect(err).to.be.an.instanceof(Error);
expect(err.errorResponse).to.deep.equal(errorDoc);
});
it(`should not construct enumerated key 'errorResponse' if present`, function () {
const errorDoc = {
message: 'A test error',
errorResponse: 'I will not be an enumerated key'
};
const err = new MongoServerError(errorDoc);
expect(err).to.be.an.instanceof(Error);
expect(err.errorResponse).to.deep.equal(errorDoc);
expect(err.errorResponse?.errorResponse).to.deep.equal('I will not be an enumerated key');
});
});
});

describe('MongoNetworkError#constructor', () => {
Expand Down

0 comments on commit 5f87446

Please sign in to comment.