UnhandledPromiseRejection on connection error.
Created by: jan-osch
I am getting an UnhandledPromiseRejectionWarning
when ECONNREFUSED is thrown on initial connection.
const Queue = require('bull');
const q = new Queue('test', 'redis://localhost:8009'); // no redis instance here
q.on('error', e => console.error('Error event', e.message));
q.process('task', 1, (job) => {
console.log('ok');
return Promise.resolve(job.id);
})
.catch(error => console.error('Failed to start consumer', error.message));
I am getting this output:
Error event connect ECONNREFUSED 127.0.0.1:8009
Error event Error initializing Lua scripts
Failed to start processing connect ECONNREFUSED 127.0.0.1:8009
(node:12173) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:8009
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1137:16)
(node:12173) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:12173) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Error event connect ECONNREFUSED 127.0.0.1:8009
Error event connect ECONNREFUSED 127.0.0.1:8009
How can I handle the UnhandledPromiseRejectionWarning
error ?