Error Handling
Under the db object, there are three functions used to send different types of messages to the frontend.
exports.load = sqlseries((db, payload) => [
db.info('loading contacts'),
db.warn('Warning message'),
db.query('selec3t * from contact', rows => {
if (rows) {
rows.forEach(t => t.gender = capitalize(t.gender))
payload.rows = rows
}
})
])
db.info('loading contacts'),
db.warn('Warning message'),
db.query('selec3t * from contact', rows => {
if (rows) {
rows.forEach(t => t.gender = capitalize(t.gender))
payload.rows = rows
}
})
])
The messages are displayed using React-Toastify on the bottom right of the screen.

info(message)(callback)
#Information messages will be popped for 0.5s then close automatically.
message: string
Information message
callback: function
Callback function supplied by sqlseries()
warn(message)(callback)
#Warning messages will be popped for 2s then close automatically.
message: string
Warning message
callback: function
Callback function supplied by sqlseries()
error(err, message, isExit)
#Error messages stay on screen. Users are required to click the close button to close.
err: object
Error object created by system.
message: string
Your custom error message
isExit: boolean
true - The request process will be terminated.
Please note that there is no callback in this function.
Error occurs during database query is captured automatically then sent to the frontend.
Follow the example below if you want to handle the error manually:
cb => db.query('selec3t * from contact', (rows, err) => {
if(err) {
// Handly your error here
db.error(err, 'SQL statement error:')
}
if (rows) {
rows.forEach(t => t.gender = capitalize(t.gender))
data.rows = rows
}
cb()
})() // <- Empty callback
if(err) {
// Handly your error here
db.error(err, 'SQL statement error:')
}
if (rows) {
rows.forEach(t => t.gender = capitalize(t.gender))
data.rows = rows
}
cb()
})() // <- Empty callback