Calling reply.send inside async middleware doesn't stop the chain
faloi opened this issue · comments
Hi @StarpTech. According to the solution you gave me in #240, I implemented a middleware using async/await
to early reply a message.
The problem is that the chain doesn't stop there, and the actual response handler gets executed. An example of this can be found at https://repl.it/repls/ScaredPassionateLifecycles:
hemera
.add({
topic: 'math',
cmd: 'add',
a: Joi.number().required(),
b: Joi.number().required()
})
.use(async function ({ payload }, reply) {
// I want to return the response here, not in the `end` method.
reply.send(180)
})
.end(async function (req) {
hemera.log.warn("This should not be called, because we are replying in the middleware")
return req.a + req.b;
}
);
With the callback approach this doesn't happen, because you can skip the call to next()
.
Great. I'm using callback style for now, will update when a new release is available.