2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +00:00
books/utils/index.js
2018-01-23 13:30:29 +05:30

21 lines
558 B
JavaScript

module.exports = {
slug(text) {
return text.toLowerCase().replace(/ /g, '_');
},
async_handler(fn) {
return (req, res, next) => Promise.resolve(fn(req, res, next))
.catch((err) => {
console.log(err);
// handle error
res.status(err ? err.status_code : 500).send({ error: err ? err.message : 'Unknown Error'});
});
},
async sleep(seconds) {
return new Promise(resolve => {
setTimeout(resolve, seconds * 1000);
});
}
}