Skip to content

Commit 5f87446

Browse files
Basic implementation done, need to UTR changes + sync spec tests still
1 parent eab8f23 commit 5f87446

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/error.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ export class MongoError extends Error {
200200
* @category Error
201201
*/
202202
export class MongoServerError extends MongoError {
203+
errorResponse?: ErrorDescription;
203204
codeName?: string;
204205
writeConcernError?: Document;
205206
errInfo?: Document;
@@ -223,9 +224,17 @@ export class MongoServerError extends MongoError {
223224
this[kErrorLabels] = new Set(message.errorLabels);
224225
}
225226

227+
this.errorResponse = message;
228+
226229
for (const name in message) {
227-
if (name !== 'errorLabels' && name !== 'errmsg' && name !== 'message')
230+
if (
231+
name !== 'errorLabels' &&
232+
name !== 'errmsg' &&
233+
name !== 'message' &&
234+
name !== 'errorResponse'
235+
) {
228236
this[name] = message[name];
237+
}
229238
}
230239
}
231240

test/unit/error.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,24 @@ describe('MongoErrors', () => {
113113
expect(err.message).to.equal(errorMessage);
114114
expect(err.someData).to.equal(12345);
115115
});
116+
context('errorResponse property', function () {
117+
it(`should set errorResponse to raw results document passed in`, function () {
118+
const errorDoc = { message: 'A test error', someData: 12345 };
119+
const err = new MongoServerError(errorDoc);
120+
expect(err).to.be.an.instanceof(Error);
121+
expect(err.errorResponse).to.deep.equal(errorDoc);
122+
});
123+
it(`should not construct enumerated key 'errorResponse' if present`, function () {
124+
const errorDoc = {
125+
message: 'A test error',
126+
errorResponse: 'I will not be an enumerated key'
127+
};
128+
const err = new MongoServerError(errorDoc);
129+
expect(err).to.be.an.instanceof(Error);
130+
expect(err.errorResponse).to.deep.equal(errorDoc);
131+
expect(err.errorResponse?.errorResponse).to.deep.equal('I will not be an enumerated key');
132+
});
133+
});
116134
});
117135

118136
describe('MongoNetworkError#constructor', () => {

0 commit comments

Comments
 (0)