doc: exceptions: keep original status_code (#331)

It is considered to be best practice for a not-found page to also use
status code 404.

This changes the examples for the 404 and 500 pages to keep the
exceptions status code.
This commit is contained in:
Daniel Hahler 2019-01-21 10:29:34 +01:00 committed by Tom Christie
parent 24ac0b44fe
commit 8545b022f9
1 changed files with 2 additions and 2 deletions

View File

@ -16,11 +16,11 @@ app = Starlette()
@app.exception_handler(404) @app.exception_handler(404)
async def not_found(request, exc): async def not_found(request, exc):
return HTMLResponse(content=HTML_404_PAGE) return HTMLResponse(content=HTML_404_PAGE, status_code=exc.status_code)
@app.exception_handler(500) @app.exception_handler(500)
async def server_error(request, exc): async def server_error(request, exc):
return HTMLResponse(content=HTML_500_PAGE) return HTMLResponse(content=HTML_500_PAGE, status_code=exc.status_code)
``` ```
If `debug` is enabled and an error occurs, then instead of using the installed If `debug` is enabled and an error occurs, then instead of using the installed