mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-27 07:12:39 +00:00
Return a basic error message when DB connection is lost
This commit is contained in:
13
server/middleware/dbCheck.js
Normal file
13
server/middleware/dbCheck.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import mongoose from 'mongoose';
|
||||
import config from '../config.js';
|
||||
|
||||
export default (req, res, next)=>{
|
||||
// Bypass DB checks during testing
|
||||
if(config.get('node_env') == 'test') return next();
|
||||
|
||||
if(mongoose.connection.readyState == 1) return next();
|
||||
return res.status(503).send({
|
||||
message : 'Unable to connect to database',
|
||||
state : mongoose.connection.readyState
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user