[WIP] Add tests to replicate failure for afterMiddleware on success #53
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This replicates the issue mentioned in #44. The afterMiddleware will be called whenever there's an error but not when the request is successful because of two reasons.
On failure, the afterMiddleware that includes four arguments in the middleware acts as the error handler as per express. So whenever there's a failure in the express router, this will be called.
On success, the fastboot middleware doesn't call
next()
to invoke this middleware but finishes off with asend()
. But then again the user must have configured the middleware with 3 arguments for the middleware to be invoked.May be it makes more sense if the afterMiddleware gets separated into an error handler and an afterResponseHook. Users need to be educated that the afterResponseHook is useful only to run operations such as logging, do post request db operations and not meant to modify the response since with
send()
we're past that.I started looking into this issue since @rwjblue suggested we can use the afterMiddleware hook to set the cache control headers for the assets folder content. It's 0 by default now. I've raised #52 for that.
If we can figure out a way forward, I can help land that.