Recovering from PoolClearedOnNetworkError, in node.js?

I am running into the following failure:

/Users/myuser/Development/myproject/node_modules/mongoose/node_modules/mongodb/src/cmap/connection_pool.ts:485
        connection.onError(new PoolClearedOnNetworkError(this));
                           ^
PoolClearedOnNetworkError: Connection to 127.0.0.1:27017 interrupted due to server monitor timeout
    at ConnectionPool.interruptInUseConnections (/Users/myuser/Development/myproject/node_modules/mongoose/node_modules/mongodb/src/cmap/connection_pool.ts:485:28)
    at <anonymous> (/Users/myuser/Development/myproject/node_modules/mongoose/node_modules/mongodb/src/cmap/connection_pool.ts:470:35)
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11) {
  address: '127.0.0.1:27017',
  [Symbol(errorLabels)]: Set(1) { 'RetryableWriteError' }
}

I am using MongoDB by means of mongoose. The application is an express based server. Both the application that is accessing MongoDB and the database itself are on a machine that can sleep and should be in an operational state when the machine wakes from sleep.

While I understand why this happens (DB timeout), based on other posts, it is not clear how I should be handling this? This typically happens when the host returns from sleep and it ends up bringing down the whole application. The only solution I have right now is to monitor the application externally and relaunch it, though I feel it would be better if there was a proper way to recover from this without an application crash.

I have added a try…catch at the top level of the application, but this doesn’t catch the error. I also tried, the following, but that doesn’t seem to be a solution either (it never gets called):

  const connection = await mongoose.connect(dbUrl, { retryReads: true });

  connection.connection.on('error', async (...args: unknown[]) => {
    logger.error(`Something went wrong: ${JSON.stringify(args)}`);
    await mongoose.connect(dbUrl, connectionOptions);
  });