diff --git a/docs/sanic/exceptions.md b/docs/sanic/exceptions.md index cffa219c..4c0888f5 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 appropriate 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 a026575a..e1136dd1 100644 --- a/sanic/exceptions.py +++ b/sanic/exceptions.py @@ -1,3 +1,5 @@ +from sanic.response import ALL_STATUS_CODES, COMMON_STATUS_CODES + TRACEBACK_STYLE = '''