-
-
Notifications
You must be signed in to change notification settings - Fork 419
Fix route with address '/client/*' not working #1307
Conversation
|
It seems a bit funny to me to check if the file exists by trying to read it and then catching the exception. Also, if we're not checking the reason for the exception we might return 404 for issues that should be a 500. Why don't we call |
|
My understanding is that checking whether a file exists before trying to open it is considered a bad practice in general (because of the race conditions this can introduce), and that you should just try to open it and then handle the exception. I'm not sure what errors that should be a 500 that you'd referring to. The idea of this change (which is what I suggested in a comment on #1142) is to pass control along to the next middleware, which would handle the route normally for URLs that don't match existing files in the built app. |
|
Ah, I hadn't considered a race condition. I was sort of assuming that files under I didn't have a specific type of error in mind that might be a 500, but I imagine reading a file might fail under rare circumstances? Permissions, file lock interrupted, file moved or deleted while reading, unsupported encoding, corrupted file, hardware error? Or maybe some user error like putting a directory name in |
|
@benmccann, I've tested with several edge cases that you've mentioned which possibly caused 500:
I think it is indeed very rare case in that part of code to generate error other than But just to make sure, maybe we can go with something like this: if (err.code === 'ENOENT') {
next();
} else {
res.statusCode = 500;
res.end('something wrong happened');
}any thought? |
|
That seems fine to me. I only wonder what should go in the |
|
@benmccann, as far as I can tell from reading the Sapper's code, this block is intended to serve static assets only. In this case any assets generated under It's just happen that if a user coincidentally defined a path named |
|
We might be talking about different I think your suggestion of the following is reasonable: I was just wondering if it would be better to do: I'm not saying it is better - just wondering to make sure we consider both options and decide which is the proper way to do things |
|
I think I'm going with the first approach for now as I'm also not too familiar with Sapper's error handling and it might become a breaking change if the error is not handled properly later. Can update it later if necessary. |
benmccann
left a comment
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.
thanks for this!!
|
Closes #1200 |
Before submitting the PR, please make sure you do the following
npm run lint!)Tests
npm testoryarn test)Fix #1142