Skip to content

Commit

Permalink
Minor issue in db error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hhassan01 committed Aug 30, 2024
1 parent 136a90b commit 214a863
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/utils/connectToDB.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import mongoose from 'mongoose'

import { InternalServerError } from './exceptions'

let cachedDbConnection: typeof mongoose | null = null

export async function connectToDatabase(): Promise<typeof mongoose> {
Expand All @@ -17,6 +19,6 @@ export async function connectToDatabase(): Promise<typeof mongoose> {
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}`)
}
}

0 comments on commit 214a863

Please sign in to comment.