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": ""

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):
      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.

Files for tornado-problem-details, version 0.0.6
Filename, size File type Python version Upload date Hashes
Filename, size tornado_problem_details-0.0.6-py2.py3-none-any.whl (6.7 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size tornado-problem-details-0.0.6.tar.gz (17.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page