Skip to content

Commit c0928f7

Browse files
committed
NODE-121 : Connection error causes Node process to terminate
1 parent eb9db70 commit c0928f7

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

lib/requester.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,14 @@ function challengeRequest(operation) {
202202
operation.logger.debug('response with status %d and %s challenge for %s',
203203
statusCode1, hasChallenge, challengeOpts.path);
204204
if ((statusCode1 === 401 && hasChallenge) || (successStatus && !isRead)) {
205-
operation.authenticator = (hasChallenge) ? createAuthenticator(
206-
operation.client, options.user, options.password, challenge
207-
) : null;
205+
try{
206+
operation.authenticator = (hasChallenge) ? createAuthenticator(
207+
operation.client, options.user, options.password, challenge
208+
) : null;
209+
210+
} catch(error){
211+
request1.emit('error', new Error('Authentication failed.'));
212+
}
208213
authenticatedRequest(operation);
209214
// should never happen
210215
} else if (successStatus && isRead) {

test-basic/client.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,24 @@ describe('database clients', function() {
107107
timestamp.value.should.equal('123');
108108
done();
109109
});
110+
it('should throw Error when server expects DIGEST and authType is CERTIFICATE', function(done) {
111+
const db = marklogic.createDatabaseClient({
112+
host: "localhost",
113+
port: 8015,
114+
authType:'certificate'
115+
});
116+
const query = marklogic.queryBuilder
117+
.where(marklogic.ctsQueryBuilder.cts.directoryQuery('/optic/test/'));
118+
119+
db.documents.query(query)
120+
.result(function (documents) {
121+
documents.forEach(function (document) {
122+
});
123+
})
124+
.catch(error =>{
125+
assert(error.toString().includes('response with invalid 401 status with path: /v1/search'));
126+
marklogic.releaseClient(db);
127+
done();
128+
});
129+
});
110130
});

0 commit comments

Comments
 (0)