Introduce a middleware that allows for HttpResponses to be thrown from inner utility functions, to avoid boilerplate in views

This commit is contained in:
Danielle McLean 2018-07-03 09:41:00 +10:00
parent 1d4be082cf
commit 7d17a92793
Signed by untrusted user: 00dani
GPG key ID: 8EB789DDF3ABD240
4 changed files with 22 additions and 9 deletions

View file

@ -17,8 +17,6 @@ def delete(request):
return error.unsupported_type(request.content_type)
url = normalise[request.content_type](request)
entry = from_url(url)
if isinstance(entry, HttpResponse):
return entry
if entry.author != request.token.user:
return error.forbid('entry belongs to another user')