-
Notifications
You must be signed in to change notification settings - Fork 156
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 calling next for Adding next() call to prepareOutput middleware [… #388
base: main
Are you sure you want to change the base?
Add calling next for Adding next() call to prepareOutput middleware [… #388
Conversation
@bamidei It might be helpful to include more details about the test failures and a link to the tests themselves.
I agree that it isn't clear why the tests include |
…utput to call next only if restify option.
@sgilroy @Zertz I've done some work on the unit and integration tests and have done a bit more research on the underlying question of whether next() should be called or not. It is my conclusion that, unfortunately, Express and Restify frameworks have different expectations/requirements around calling next() in this case. For Restify, it is required to call next() and for Express it is not required/recommended and actually causes problems. I've updated the change to reflect this - using the config.restify option which is already present to determine whether or not to call next() from prepareOutput middleware. A few additional notes:
|
@@ -49,10 +49,20 @@ module.exports = function (options, excludedMap) { | |||
if (options.postProcess) { | |||
if (promise && typeof promise.then === 'function') { | |||
promise.then(() => { | |||
options.postProcess(req, res) | |||
options.postProcess(req, res); | |||
if (options.restify) { |
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.
Codacy has a fix for the issue: Replace ············
with ··············
if (options.restify) { | |
if (options.restify) { |
sinon.assert.notCalled(onError) | ||
sinon.assert.calledOnce(next) | ||
done() | ||
}); |
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.
Codacy has a fix for the issue: Delete ;
}); | |
}) |
options.postProcess(req, res) | ||
options.postProcess(req, res); | ||
if (options.restify) { | ||
next(); |
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.
Codacy has a fix for the issue: Replace next();
with ··next()
next(); | |
next() |
…#337]
This fixes an issue whereby any middleware registered to occur after would not be called. The specific situation which we have which triggers this is a call to server.on('after', ) where server is a restify server instance. The specified middleware will never be called without this fix.
I notice that you have specific unit tests to ensure that next is not called from prepareOutput. If you would like to not merge this PR instead of changing those tests, could you please explain the reasoning for this? Also, the latest version removed the next parameter from being passed to the postProcess optional parameter which prevents an easy work-around for this not being called in prepareOutput.