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 call send_error() with additional parameters.

from tornado import web
import problemdetails


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")
HTTP/1.1 500 Internal Server Error
Content-Type: application/problem+json

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

As an alternative, you can raise a problemdetails.Problem instance and let the Tornado exception handling take care of eventually calling write_error. The following snippet produces the same output as the previous example.

from tornado import web
import problemdetails


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')

The problemdetails.Problem instance passes all of the keyword parameters through in the resulting message so it is very easy to add fields. The interface of tornado.web.RequestHandler.send_error is less expressive since keyword parameters may be swallowed by intervening code.

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.2.tar.gz (7.1 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.2-py2.py3-none-any.whl (6.1 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: tornado-problem-details-0.0.2.tar.gz
  • Upload date:
  • Size: 7.1 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.2.tar.gz
Algorithm Hash digest
SHA256 ba7ee67badfadc308c54edba2e216bdec606100a95f1630efa3ce585baf8e86d
MD5 6a98e44459f0df3bf7cde54e26f8351f
BLAKE2b-256 299d8cc0d348e7c71e1213660e1b7be52e64f7168817fa793f54e1f2ab3132c1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tornado_problem_details-0.0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.1 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.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 51dccf78d51ac81c4adc4d5d1de77fee14db17cd18f826c0add9ef4af86b9a4a
MD5 40f667fa2555b26ff8afa4d771e9994d
BLAKE2b-256 8f4629df8b860d0ce38e29c7d19bc900b3d5e2f1adf79a6cc1744dd6dbc94f1a

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