Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling reply.send inside async middleware doesn't stop the chain #244

Closed
faloi opened this issue Oct 16, 2019 · 2 comments · Fixed by #245
Closed

Calling reply.send inside async middleware doesn't stop the chain #244

faloi opened this issue Oct 16, 2019 · 2 comments · Fixed by #245

Comments

@faloi
Copy link

faloi commented Oct 16, 2019

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().

@StarpTech
Copy link
Member

Hi @faloi thanks for reporting. This is a bug. I will provide a fix in #245 please have a look.

@faloi
Copy link
Author

faloi commented Oct 16, 2019

Great. I'm using callback style for now, will update when a new release is available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants