2018-01-12 12:25:07 +00:00
|
|
|
module.exports = {
|
|
|
|
slug(text) {
|
|
|
|
return text.toLowerCase().replace(/ /g, '_');
|
|
|
|
},
|
|
|
|
|
|
|
|
async_handler(fn) {
|
|
|
|
return (req, res, next) => Promise.resolve(fn(req, res, next))
|
2018-01-15 11:55:31 +00:00
|
|
|
.catch((err) => {
|
2018-01-23 08:00:29 +00:00
|
|
|
console.log(err);
|
2018-01-15 11:55:31 +00:00
|
|
|
// handle error
|
2018-01-23 12:26:40 +00:00
|
|
|
res.status(err.status_code || 500).send({error: err.message});
|
2018-01-15 11:55:31 +00:00
|
|
|
});
|
2018-01-12 12:25:07 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
async sleep(seconds) {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
setTimeout(resolve, seconds * 1000);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|