Skip to main content

RFC-7807 Error documents for Tornado

Project description

build coverage docs download license source

This library provides a version of tornado.web.RequestHandler.send_error that speaks application/problem+json instead of HTML. The easiest way to use this library is to inherit from problemdetails.ErrorWriter and raise problemdetails.Problem exceptions instead of HTTPError.

class MyHandler(problemdetails.ErrorWriter, web.RequestHandler):
   def get(self):
      if not self.do_something_hard():
         raise problemdetails.Problem(status_code=500,
                                      title='Failed to do_something_hard')
HTTP/1.1 500 Internal Server Error
Content-Type: application/problem+json

{
   "status": 500,
   "title": "Failed to do_something_hard",
   "type": "https://tools.ietf.org/html/rfc7231#section-6.6.1"
}

You can easily construct more substantial response documents by passing additional keyword parameters to the problemdetails.Problem initializer. They become top-level properties in the response document.

You can also call send_error directly and produce a response docuemnt. The following snippet produces the same output as the previous snippet.

class MyHandler(problemdetails.ErrorWriter, web.RequestHandler):
   def get(self):
      try:
         self.do_something_hard()
      except SomeException as error:
         self.send_error(500, title="Failed to do_something_hard")

The interface of tornado.web.RequestHandler.send_error is less expressive since keyword parameters may be swallowed by intervening code. The only parameters that are recognized are: instance, title, and type. Use the exception-based interface for more substantial documents.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tornado-problem-details-0.0.6.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tornado_problem_details-0.0.6-py2.py3-none-any.whl (6.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file tornado-problem-details-0.0.6.tar.gz.

File metadata

  • Download URL: tornado-problem-details-0.0.6.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for tornado-problem-details-0.0.6.tar.gz
Algorithm Hash digest
SHA256 ba3846a15fead7f342b1bec0a2236825f2db9ca4fd793f14e8838b85c62d61c0
MD5 179f49348ecdc2570063f8e46a2932f8
BLAKE2b-256 99e9f323b4caa1d7f9d5d034e34119916599befd9f50918b2c735a692a6a5b75

See more details on using hashes here.

File details

Details for the file tornado_problem_details-0.0.6-py2.py3-none-any.whl.

File metadata

  • Download URL: tornado_problem_details-0.0.6-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for tornado_problem_details-0.0.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 71ab2b55c35dc7227579d408c51a1ed4ea53866b75a606c274ea93d98d2e2aa3
MD5 f35f83c7d100533e4046bd0f9ae5a9d6
BLAKE2b-256 6c389b500bdf41f154de4e220876708f6a31ed470dae30027e323d57d10f57ec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page