Nodejs ile ele alinmamis promise.rejectleri yakamalar
typescript, programming

process.on
ile yakalayabilirizBu örnekte,
new Promise
içindeki işlev hemen bir hata ile reddedilir, ancak bu hata hiçbir yerde yakalanmaz. Bu durumda, 'unhandledRejection' olayı tetiklenir ve belirtilen işlev çalıştırılır. Bu işlev, reddedilen promise'i ve reddetme nedenini konsola yazar.
process.on('unhandledRejection', (reason, promise) => {
console.log('Unhandled Rejection at:', promise, 'reason:', reason);
// Application specific logging, throwing an error, or other logic here
});
new Promise((resolve, reject) => {
reject(new Error('Test Error'));
});

Last updated
Was this helpful?