raise exception for _static_request_handler
unknown exception; add test with custom error (#2195)
Co-authored-by: n.feofanov <n.feofanov@visionlabs.ru> Co-authored-by: Adam Hopkins <admhpkns@gmail.com>
This commit is contained in:
parent
1b8cb742f9
commit
7b7a572f9b
@ -781,6 +781,7 @@ class RouteMixin:
|
|||||||
path={file_or_directory}, "
|
path={file_or_directory}, "
|
||||||
f"relative_url={__file_uri__}"
|
f"relative_url={__file_uri__}"
|
||||||
)
|
)
|
||||||
|
raise
|
||||||
|
|
||||||
def _register_static(
|
def _register_static(
|
||||||
self,
|
self,
|
||||||
|
@ -461,6 +461,22 @@ def test_nested_dir(app, static_file_directory):
|
|||||||
assert response.text == "foo\n"
|
assert response.text == "foo\n"
|
||||||
|
|
||||||
|
|
||||||
|
def test_handle_is_a_directory_error(app, static_file_directory):
|
||||||
|
error_text = "Is a directory. Access denied"
|
||||||
|
app.static("/static", static_file_directory)
|
||||||
|
|
||||||
|
@app.exception(Exception)
|
||||||
|
async def handleStaticDirError(request, exception):
|
||||||
|
if isinstance(exception, IsADirectoryError):
|
||||||
|
return text(error_text, status=403)
|
||||||
|
raise exception
|
||||||
|
|
||||||
|
request, response = app.test_client.get("/static/")
|
||||||
|
|
||||||
|
assert response.status == 403
|
||||||
|
assert response.text == error_text
|
||||||
|
|
||||||
|
|
||||||
def test_stack_trace_on_not_found(app, static_file_directory, caplog):
|
def test_stack_trace_on_not_found(app, static_file_directory, caplog):
|
||||||
app.static("/static", static_file_directory)
|
app.static("/static", static_file_directory)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user