This commit is contained in:
Channel Cat 2016-10-14 04:58:09 -07:00
parent 5a7447e975
commit 35ed7ceefb
4 changed files with 8 additions and 4 deletions

View File

@ -1,6 +1,6 @@
# Exceptions
Check sanic.exceptions for a list of exceptions
Exceptions can be thrown from within request handlers and will automatically be handled by Sanic. Exceptions take a message as their first argument, and can also take a status_code to be passed back in the HTTP response. Check sanic.exceptions for the full list of exceptions to throw.
## Throwing an exception

View File

@ -5,8 +5,8 @@ Make sure you have pip and python 3.5 before starting
## Benchmarks
* Install Sanic
* `python3 -m pip install git+https://github.com/channelcat/sanic/`
* Edit main.py
* ```python3
* Edit main.py to include:
```python
from sanic import Sanic
from sanic.response import json

View File

@ -10,6 +10,10 @@ Middleware is registered via the middleware decorator, and can either be added a
app = Sanic('__name__')
@app.middleware
async def halt_request(request):
print("I am a spy")
@app.middleware('request')
async def halt_request(request):
return text('I halted the request')

View File

@ -7,7 +7,7 @@ Sanic comes with a basic router that supports request parameters. To specify a
```python
from sanic import Sanic
from sanic.response import json
from sanic.response import text
@app.route('/tag/<tag>')
async def person_handler(request, tag):