Merge pull request #740 from r0fls/739

add abort function
This commit is contained in:
Raphael Deem
2017-05-21 02:20:02 -07:00
committed by GitHub
3 changed files with 77 additions and 12 deletions

View File

@@ -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`