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-1.1.0.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

tornado_problem_details-1.1.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file tornado_problem_details-1.1.0.tar.gz.

File metadata

File hashes

Hashes for tornado_problem_details-1.1.0.tar.gz
Algorithm Hash digest
SHA256 918974c8bf892fd2b239ffa7b9f569d3cfadb8d3cd07def1e02c64827c3a298e
MD5 b8620d7f81293abe8708773068ea03ed
BLAKE2b-256 b3398bb6ef0554ecc4f8adc9ef6e05ebe2102e33d2269258f4e06d4c5f459c58

See more details on using hashes here.

File details

Details for the file tornado_problem_details-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tornado_problem_details-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7d93cc4233f3bfbf86df341f3c7cf8d0547cc911ff92b5c53e5fdbc44ed69126
MD5 859ad501701531e1cbb369f5b7254a0a
BLAKE2b-256 1127df44f88fa4efff5d0f20de8ad4aedc3f2c7e0df3f350fe3b8477bf5ddac2

See more details on using hashes here.

Supported by

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