Skip to content

Commit 6110ddd

Browse files
committed
Do not process FileNotFoundError in FileResponse, resolves encode#979
FileNotFoundError can be processed in exception_handlers
1 parent cbddcaf commit 6110ddd

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

starlette/responses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
341341
stat_result = await anyio.to_thread.run_sync(os.stat, self.path)
342342
self.set_stat_headers(stat_result)
343343
except FileNotFoundError:
344-
raise RuntimeError(f"File at path {self.path} does not exist.")
344+
pass
345345
else:
346346
mode = stat_result.st_mode
347347
if not stat.S_ISREG(mode):

tests/test_responses.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,8 @@ def test_file_response_with_missing_file_raises_error(tmp_path: Path, test_clien
299299
path = tmp_path / "404.txt"
300300
app = FileResponse(path=path, filename="404.txt")
301301
client = test_client_factory(app)
302-
with pytest.raises(RuntimeError) as exc_info:
302+
with pytest.raises(FileNotFoundError) as exc_info:
303303
client.get("/")
304-
assert "does not exist" in str(exc_info.value)
305304

306305

307306
def test_file_response_with_chinese_filename(tmp_path: Path, test_client_factory: TestClientFactory) -> None:

0 commit comments

Comments
 (0)