Metadata-Version: 2.1
Name: tornado-problem-details
Version: 0.0.4
Summary: RFC-7807 Error documents for Tornado
Home-page: https://github.com/dave-shawley/tornado-problem-details
Author: Dave Shawley
Author-email: daveshawley@gmail.com
License: UNKNOWN
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
Classifier: Topic :: Software Development :: Libraries
Requires-Dist: tornado (>=4.4)
Provides-Extra: dev
Requires-Dist: coverage (==4.5.3) ; extra == 'dev'
Requires-Dist: flake8 (==3.7.7) ; extra == 'dev'
Requires-Dist: flake8-fixme (==1.1.0) ; extra == 'dev'
Requires-Dist: flake8-print (==3.1.0) ; extra == 'dev'
Requires-Dist: nose (==1.3.7) ; extra == 'dev'
Requires-Dist: readme-renderer (==24.0) ; extra == 'dev'
Requires-Dist: sphinx (==2.0.0) ; extra == 'dev'
Requires-Dist: tox (==3.8.4) ; extra == 'dev'
Requires-Dist: twine (==1.13.0) ; extra == 'dev'
Requires-Dist: wheel (==0.33.1) ; extra == 'dev'
Requires-Dist: yapf (==0.26.0) ; extra == 'dev'
Provides-Extra: docs
Requires-Dist: sphinx (==2.0.0) ; extra == 'docs'

RFC-7807 implementation for Tornado
===================================
|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.

.. code-block:: python

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

.. code-block:: http

   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.

.. code-block:: python

   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.

.. |build| image:: https://img.shields.io/circleci/project/github/dave-shawley/tornado-problem-details/master.svg?style=social
   :target: https://circleci.com/gh/dave-shawley/tornado-problem-details/tree/master
.. |coverage| image:: https://img.shields.io/coveralls/github/dave-shawley/tornado-problem-details.svg?style=social
   :target: https://coveralls.io/github/dave-shawley/tornado-problem-details?branch=master
.. |docs| image:: https://img.shields.io/readthedocs/tornado-problem-details.svg?style=social
   :target: https://tornado-problem-details.readthedocs.io/en/latest/?badge=latest
.. |download| image:: https://img.shields.io/pypi/pyversions/tornado-problem-details.svg?style=social
   :target: https://pypi.org/project/tornado-problem-details/
.. |license| image:: https://img.shields.io/pypi/l/tornado-problem-details.svg?style=social
   :target: https://github.com/dave-shawley/tornado-problem-details/blob/master/LICENSE.txt
.. |source| image:: https://img.shields.io/badge/source-github.com-green.svg?style=social
   :target: https://github.com/dave-shawley/tornado-problem-details


