Skip to content

Commit

Permalink
Making static route more verbose if file not found (#1945)
Browse files Browse the repository at this point in the history

Co-authored-by: Adam Hopkins <[email protected]>
  • Loading branch information
tomaszdrozdz and ahopkins authored Dec 28, 2020
1 parent 449bc41 commit 7475897
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sanic/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
InvalidUsage,
)
from sanic.handlers import ContentRangeHandler
from sanic.log import error_logger
from sanic.response import HTTPResponse, file, file_stream


Expand Down Expand Up @@ -40,6 +41,10 @@ async def _static_request_handler(
# match filenames which got encoded (filenames with spaces etc)
file_path = path.abspath(unquote(file_path))
if not file_path.startswith(path.abspath(unquote(root_path))):
error_logger.exception(
f"File not found: path={file_or_directory}, "
f"relative_url={file_uri}"
)
raise FileNotFound(
"File not found", path=file_or_directory, relative_url=file_uri
)
Expand Down Expand Up @@ -94,6 +99,10 @@ async def _static_request_handler(
except ContentRangeError:
raise
except Exception:
error_logger.exception(
f"File not found: path={file_or_directory}, "
f"relative_url={file_uri}"
)
raise FileNotFound(
"File not found", path=file_or_directory, relative_url=file_uri
)
Expand Down

0 comments on commit 7475897

Please sign in to comment.