Skip to content

Instantly share code, notes, and snippets.

@fabiobusnello
Created September 12, 2018 15:18
Show Gist options
  • Save fabiobusnello/617d047e258d987ac828e7fc95e5e1ab to your computer and use it in GitHub Desktop.
Save fabiobusnello/617d047e258d987ac828e7fc95e5e1ab to your computer and use it in GitHub Desktop.
ERRORS express
const fs = require('fs')
const moment = require('moment')
const errors = (err, res) => {
if(!err)return false
const logName = moment().format('DD_MM_YYYY-HH_mm_ss_SSS') + '.txt'
if(res){
res.status(500).json({status: false, message: "Erro interno no servidor, log disponível apneas no servidor em /logs/errors/DATA_HORA_MILLESEGUNDOS.txt"})
}
fs.writeFile(__dirname + '/../logs/errors/' + logName, err.stack || err, err=>{
if(err)return console.log(err)
})
}
module.exports = errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment