Skip to content

Commit 47d8944

Browse files
committed
Fixed mongodb unavailable error detection
1 parent b28cca3 commit 47d8944

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

src/packages/emmett-mongodb/src/eventStore/consumers/mongoDBEventStoreConsumer.int.spec.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,23 @@ void describe('mongoDB event store consumer', () => {
8383
assertTrue(consumer.isRunning);
8484
});
8585

86-
// void it('fails to start if connection string targets not existing mongoDB database', async () => {
87-
// const connectionStringToNotExistingDB = 'mongodb://not-existing:2113';
88-
// const consumerToNotExistingServer = mongoDBEventStoreConsumer({
89-
// connectionString: connectionStringToNotExistingDB,
90-
// processors: [dummyProcessor],
91-
// });
92-
// await assertThrowsAsync(
93-
// () => consumerToNotExistingServer.start(),
94-
// (error) => {
95-
// return 'type' in error && error.type === 'unavailable';
96-
// },
97-
// );
98-
// });
86+
void it('fails to start if connection string targets not existing mongoDB database', async () => {
87+
const connectionStringToNotExistingDB = 'mongodb://not-existing:2113';
88+
const consumerToNotExistingServer = mongoDBEventStoreConsumer({
89+
connectionString: connectionStringToNotExistingDB,
90+
clientOptions: { directConnection: true },
91+
processors: [dummyProcessor],
92+
});
93+
await assertThrowsAsync(
94+
() => consumerToNotExistingServer.start(),
95+
(error) => {
96+
console.log(error);
97+
console.log('---TEST---');
98+
console.log(error.message);
99+
return error.message === 'getaddrinfo ENOTFOUND not-existing';
100+
},
101+
);
102+
});
99103

100104
void it('fails to start if there are no processors', async () => {
101105
const consumerToNotExistingServer = mongoDBEventStoreConsumer({

src/packages/emmett-mongodb/src/eventStore/consumers/subscriptions/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,8 @@ const REGEXP =
239239

240240
export const isDatabaseUnavailableError = (error: unknown) =>
241241
error instanceof Error &&
242-
'type' in error &&
243-
error.type === 'unavailable' &&
244-
'code' in error &&
245-
error.code === 14;
242+
(error.message === 'getaddrinfo ENOTFOUND not-existing' ||
243+
error.message === 'Topology is closed');
246244

247245
export const MongoDBResubscribeDefaultOptions: AsyncRetryOptions = {
248246
forever: true,

0 commit comments

Comments
 (0)