Last active
August 29, 2021 14:14
-
-
Save msacar/e8a47d1863dbb0a023f3344cd029715a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const process = require("process"); | |
const fs = require("fs"); | |
//Error.log dosyasına hatayı yazar | |
process.on('uncaughtException', (err, reason) => { | |
fs.appendFileSync( | |
'error.log', | |
`\n[${new Date().toISOString()}] ${reason}: ${err}\n` + | |
`Stack: ${err.stack}\n`, | |
{ flag: 'a+' } | |
); | |
process.exit(1) | |
}); | |
//Error.log dosyasına hatayı yazar | |
process.on('unhandledRejection', (err, promise) => { | |
fs.appendFileSync( | |
'error.log', | |
`\n[${new Date().toISOString()}] ${err}\n` + | |
`Stack: ${err.stack}\n` , | |
{ flag: 'a+' } | |
); | |
process.exit(1) | |
}) | |
// Olmayan bir fonksiyonu çağırdığımız için ve catch etmediğimiz için Uncaught Exception üretir. | |
// nonexistentFunc(); | |
// Promise reject olduğu için ve catch etmediğimiz için Unhandled Rejection üretir. | |
unhandledRejection() | |
function unhandledRejection(){ | |
new Promise((resolve,reject)=>{ | |
reject(new Error('Promise resolve olamıyor hatası')) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment