Skip to content

Commit

Permalink
Merge pull request #527 from Cornices/je/issue-526
Browse files Browse the repository at this point in the history
Document combining `request.error` with Pyramid exceptions.
  • Loading branch information
leplatrem committed Feb 27, 2020
2 parents c8ed6d9 + 28bab0e commit 8289016
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions docs/source/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ mapping. Add the following code to :file:`messaging/views.py`:
import os
import binascii
from pyramid.httpexceptions import HTTPUnauthorized
from pyramid.httpexceptions import HTTPUnauthorized, HTTPConflict
def _create_token():
Expand Down Expand Up @@ -197,15 +197,16 @@ mapping. Add the following code to :file:`messaging/views.py`:
name = request.text
if name in _USERS:
request.errors.add('url', 'name', 'This user exists!')
else:
user = {'name': name, 'token': _create_token()}
request.validated['user'] = user
raise HTTPConflict()
user = {'name': name, 'token': _create_token()}
request.validated['user'] = user
The validators work by filling the **request.validated**
dictionary. When the validator finds errors, it adds them to the
**request.errors** dictionary, and that will return a 400 with the
errors.
**request.errors** dictionary and raises a Conflict (409) error.
Note that raising an error here still honors Cornice's built-in
`request errors <https://cornice.readthedocs.io/en/latest/api.html#errors>`_.

Let's try our application so far with CURL::

Expand Down

0 comments on commit 8289016

Please sign in to comment.