diff --git a/docs/sanic/exceptions.md b/docs/sanic/exceptions.md index cffa219c..6b68cd3e 100644 --- a/docs/sanic/exceptions.md +++ b/docs/sanic/exceptions.md @@ -17,6 +17,19 @@ def i_am_ready_to_die(request): raise ServerError("Something bad happened", status_code=500) ``` +You can also use the `abort` function with the correct status code: + +```python +from sanic.exceptions import abort +from sanic.response import text + +@app.route('/youshallnotpass') +def no_no(request): + abort(401) + # this won't happen + text("OK") +``` + ## Handling exceptions To override Sanic's default handling of an exception, the `@app.exception` diff --git a/sanic/exceptions.py b/sanic/exceptions.py index 45c17ef0..989de72d 100644 --- a/sanic/exceptions.py +++ b/sanic/exceptions.py @@ -1,4 +1,4 @@ -from sanic.response import ALL_STATUS_CODES +from sanic.response import ALL_STATUS_CODES, COMMON_STATUS_CODES TRACEBACK_STYLE = '''