From 214a863debc74642d1e0c9686bfb66264381e9e6 Mon Sep 17 00:00:00 2001 From: hhassan01 Date: Fri, 30 Aug 2024 11:00:52 +0500 Subject: [PATCH] Minor issue in db error handling --- src/utils/connectToDB.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/utils/connectToDB.ts b/src/utils/connectToDB.ts index 0d1f357..39c2c71 100644 --- a/src/utils/connectToDB.ts +++ b/src/utils/connectToDB.ts @@ -1,5 +1,7 @@ import mongoose from 'mongoose' +import { InternalServerError } from './exceptions' + let cachedDbConnection: typeof mongoose | null = null export async function connectToDatabase(): Promise { @@ -17,6 +19,6 @@ export async function connectToDatabase(): Promise { return cachedDbConnection } catch (error: any) { cachedDbConnection = null - throw new Error(`Failed to connect to MongoDB: ${error.message}`) + throw new InternalServerError(`Failed to connect to MongoDB: ${error.message}`) } }