From ecf5adb0b07aca7336800e5aebb3922502d8290d Mon Sep 17 00:00:00 2001 From: chornos13 Date: Sat, 17 Sep 2022 12:35:30 +0700 Subject: [PATCH 1/2] fix: clear cached promise if there's an error while connecting --- examples/with-mongodb-mongoose/lib/dbConnect.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/with-mongodb-mongoose/lib/dbConnect.js b/examples/with-mongodb-mongoose/lib/dbConnect.js index 698a02e5c46e..3a7789cc4665 100644 --- a/examples/with-mongodb-mongoose/lib/dbConnect.js +++ b/examples/with-mongodb-mongoose/lib/dbConnect.js @@ -33,7 +33,14 @@ async function dbConnect() { return mongoose }) } - cached.conn = await cached.promise + + try { + cached.conn = await cached.promise + } catch (e) { + cached.promise = null + throw e + } + return cached.conn } From 2f372c1a6b284e12a764ea3156237fdf4a36b8d9 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Mon, 19 Sep 2022 14:20:35 -0700 Subject: [PATCH 2/2] lint fix --- examples/with-mongodb-mongoose/lib/dbConnect.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/with-mongodb-mongoose/lib/dbConnect.js b/examples/with-mongodb-mongoose/lib/dbConnect.js index 3a7789cc4665..f8bca3635137 100644 --- a/examples/with-mongodb-mongoose/lib/dbConnect.js +++ b/examples/with-mongodb-mongoose/lib/dbConnect.js @@ -33,14 +33,14 @@ async function dbConnect() { return mongoose }) } - + try { cached.conn = await cached.promise } catch (e) { cached.promise = null throw e } - + return cached.conn }