Making static route more verbose if file not found (#1945)
Co-authored-by: Adam Hopkins <admhpkns@gmail.com>
This commit is contained in:
parent
449bc417a3
commit
7475897a03
|
@ -13,6 +13,7 @@ from sanic.exceptions import (
|
||||||
InvalidUsage,
|
InvalidUsage,
|
||||||
)
|
)
|
||||||
from sanic.handlers import ContentRangeHandler
|
from sanic.handlers import ContentRangeHandler
|
||||||
|
from sanic.log import error_logger
|
||||||
from sanic.response import HTTPResponse, file, file_stream
|
from sanic.response import HTTPResponse, file, file_stream
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,6 +41,10 @@ async def _static_request_handler(
|
||||||
# match filenames which got encoded (filenames with spaces etc)
|
# match filenames which got encoded (filenames with spaces etc)
|
||||||
file_path = path.abspath(unquote(file_path))
|
file_path = path.abspath(unquote(file_path))
|
||||||
if not file_path.startswith(path.abspath(unquote(root_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(
|
raise FileNotFound(
|
||||||
"File not found", path=file_or_directory, relative_url=file_uri
|
"File not found", path=file_or_directory, relative_url=file_uri
|
||||||
)
|
)
|
||||||
|
@ -94,6 +99,10 @@ async def _static_request_handler(
|
||||||
except ContentRangeError:
|
except ContentRangeError:
|
||||||
raise
|
raise
|
||||||
except Exception:
|
except Exception:
|
||||||
|
error_logger.exception(
|
||||||
|
f"File not found: path={file_or_directory}, "
|
||||||
|
f"relative_url={file_uri}"
|
||||||
|
)
|
||||||
raise FileNotFound(
|
raise FileNotFound(
|
||||||
"File not found", path=file_or_directory, relative_url=file_uri
|
"File not found", path=file_or_directory, relative_url=file_uri
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user