-
Notifications
You must be signed in to change notification settings - Fork 450
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
Add new "reply" middleware action #278
Conversation
The "reply" middleware is called just before the backend is about to reply to a client. It's the flip side of the existing "receive" middleware action. The middleware function gets a context with properties: - request - reply - action (always `'reply'` for this middleware) - agent - backend
lib/agent.js
Outdated
this.send(request); | ||
request.error = getReplyErrorObject(err); | ||
var middlewareContext = {request: request, reply: request}; | ||
backend.trigger(backend.MIDDLEWARE_ACTIONS.reply, agent, middlewareContext, function(_err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have an error, let's not emitted the middleware event instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good when the tests pass.
Released in [email protected] |
What is the purpose of the "reply" middleware? I see there is no documentation at all added in this PR. The tests serve as the documentation. |
Whatever, really - a couple example use-cases:
It's a pretty low-level middleware, sitting just above the messaging layer, similar to the existing 'receive' middleware.
I indeed forgot to update the README, thanks for the reminder! Just made a new PR for it: #279 |
The "reply" middleware is called just before the backend is about to send a non-error reply to a client.
It's the flip side of the existing "receive" middleware action.
The middleware function gets a context with these properties:
'reply'
for this middleware)