Hallo to everyone, i have one question. I have res...
# orm-help
g
Hallo to everyone, i have one question. I have rest api and one endpoint is with GET to monitoring database. How can I handle DB Exceptions and logg if the are any issues?
r
Simply using an error handling mechanism like
try/catch
should work here. What have you currently implemented?
g
Copy code
app.get('/monitoring', async (req, res) => {
    try{
        const count = await prisma.users.count();
        if (count) {
            res.status(200).json({
                "Status": 'OK',
                "v": module.exports.version
            })
        } else {
            throw error
        }
    }catch(err){
       console.log(JSON.stringify(err),'error')
        console.log(err,'error')
        res.status(500).json({
            "Status": "Not OK",
            "v": module.exports.version,
            "message":err.message
        })
    }
Here is my get endpoint, but what I want to handle the db Exception