-
Notifications
You must be signed in to change notification settings - Fork 85
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
Does not throw when file does not exist #43
Comments
See https://github.com/koajs/send/blob/master/index.js#L92 var notfound = ['ENOENT', 'ENAMETOOLONG', 'ENOTDIR'];
if (~notfound.indexOf(err.code)) return; You can check that by this var path = yield send(...);
if (!path) {
// do something ...
} |
I see, however it's not what I (and I presume most would have) expected. Not throwing on missing file lead me to waste an hour trying to find what the problem is. I think it's logical to have the default behavior throw an error when the file does not exist - on top of that this behavior is not documented. Especially that with throwing - it's as simple as try-catching the send for the end-user. |
It's reasonable for me to respond |
|
Hmm it should still be logged, if you have a logger. If not I would say that's a logger bug, or it is not the top-most middleware. The absence of a response is a 404 implicitly, but having the error code etc sounds useful, throwing sounds reasonable to me |
@tj Exactly. |
Haha yeah true, I find that with 404's all the time, hard to tell if it's a result of something missing in the db etc or just some screwed up route, little ambiguous. SGTM |
@tj So, we need to do a broken change like this? if (~notfound.indexOf(err.code)) {
err.status = 404;
throw err;
} |
Yep! I think that should be good, can't think of any weird side-effects at the moment |
@m-brian take a look at koajs/static#62 #47 It's not the topic of this issue. |
may be it would be better to add a option: |
Throwing an error if something went wrong is simply convenient and intuitive, why one should check a result if no file found? It's purpose is to serve files and if requested path does not resolve it is wrong and it should throw. |
|
If a file does not exist there is no error. The promise resolves because and returns
undefined
on theyield fs.stat
here:Not sure if that's a bug in
mz
or with the usage by koa-send.The text was updated successfully, but these errors were encountered: