.
This commit is contained in:
parent
5a7447e975
commit
35ed7ceefb
|
@ -1,6 +1,6 @@
|
||||||
# Exceptions
|
# 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
|
## Throwing an exception
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@ Make sure you have pip and python 3.5 before starting
|
||||||
## Benchmarks
|
## Benchmarks
|
||||||
* Install Sanic
|
* Install Sanic
|
||||||
* `python3 -m pip install git+https://github.com/channelcat/sanic/`
|
* `python3 -m pip install git+https://github.com/channelcat/sanic/`
|
||||||
* Edit main.py
|
* Edit main.py to include:
|
||||||
* ```python3
|
```python
|
||||||
from sanic import Sanic
|
from sanic import Sanic
|
||||||
from sanic.response import json
|
from sanic.response import json
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,10 @@ Middleware is registered via the middleware decorator, and can either be added a
|
||||||
app = Sanic('__name__')
|
app = Sanic('__name__')
|
||||||
|
|
||||||
@app.middleware
|
@app.middleware
|
||||||
|
async def halt_request(request):
|
||||||
|
print("I am a spy")
|
||||||
|
|
||||||
|
@app.middleware('request')
|
||||||
async def halt_request(request):
|
async def halt_request(request):
|
||||||
return text('I halted the request')
|
return text('I halted the request')
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ Sanic comes with a basic router that supports request parameters. To specify a
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from sanic import Sanic
|
from sanic import Sanic
|
||||||
from sanic.response import json
|
from sanic.response import text
|
||||||
|
|
||||||
@app.route('/tag/<tag>')
|
@app.route('/tag/<tag>')
|
||||||
async def person_handler(request, tag):
|
async def person_handler(request, tag):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user