-
Notifications
You must be signed in to change notification settings - Fork 242
Conversation
kitsonk
commented
May 29, 2021
Why not use an error middleware, like in the examples/staticServer.ts?
Lines 18 to 53 in a9c56c7
That is the more common pattern of handling errors in a middleware application.
jsejcksn
commented
May 29, 2021
Why not use an error middleware
@kitsonk I'm not sure what you mean. Do you mean adding a general purpose error handling middleware function in addition to the stack in the example?
The purpose of adding this documentation is:
- to point out that
send()throws when a match isn't found, and - to detail the specifics of the exception thrown:
- The exception is an instance of
HttpError(ex instanceof HttpError) exception.statusis equal to404(ex.status === Status.NotFound)
- The exception is an instance of
jsejcksn
commented
Jun 29, 2021
Hi @kitsonk
Do you have more feedback for showing users how to use send() first in their middleware stack so that filesystem has priority over other middleware?
I'd love to make any changes needed so that this documentation can be merged and others won't have to go through the same confusion that I did before doing a review of this middleware source code.
CLA assistant check
All committers have signed the CLA.
twhitbeck
commented
Sep 11, 2021
fwiw I found this PR extremely helpful. I also went through a bit of confusion when using send. I figured send itself could be configured to either terminate with 404 or fall through to the next middleware (like https://github.com/expressjs/serve-static#fallthrough).
ca1a03b to
a4104a6
Compare
364918e to
244f634
Compare
Resolves #331
This documents the specific error thrown by
send()when no filesystem entry is matched to the request path, and adds an example of how to handle the error in order to usesend()in other positions in the middleware stack besides the very end.