Error handling

Hi, Currently this how I handle the database error thrown from Drizzle,
try {
...
} catch (error) {
if (error.sqlMessage) {
// toast a message "There was database error, contact administrator"
} else {
...
}
}
try {
...
} catch (error) {
if (error.sqlMessage) {
// toast a message "There was database error, contact administrator"
} else {
...
}
}
Is this the correct way to check if it is a database error?
2 Replies
AndréLB
AndréLB2mo ago
Pretty much what I am doing except I have a function in the catch block which I reuse. Move the if-else to a separate function that can be reused and you should be good to go.
jack
jack2mo ago
how do you type narrow to know that sqlMessage is present on error?
Want results from more Discord servers?
Add your server