Reference¶
- class problemdetails.ErrorWriter(application: tornado.web.Application, request: tornado.httputil.HTTPServerRequest, **kwargs: Any)[source]¶
Render application/problem+json in
write_error
Include this class in the base class list to return errors as application/problem+json documents instead of HTML.
- PROBLEM_DETAILS_MIME_TYPE¶
This class-level attribute controls the content type used by write_error. Due to the way that write_error is called, it is necessary to configure this. Setting the content type header before calling
send_error()
DOES NOT work as expected.If you need to change the response content type, change this attribute at the class-level.
- json_encoder = <json.encoder.JSONEncoder object>¶
Used to encode problem response documents.
You set the attributes of this encoder to customize the creation of problem documents.
- write_error(status_code: int, **kwargs: Any) None [source]¶
Render application/problem+json documents instead of HTML.
- Parameters
status_code – HTTP status code that we returned
detail (str) – optional detail field to include in the error document. This field is omitted by default.
instance (str) – optional instance to include in the error document. This field is omitted by default.
title (str) – optional title to include in the error document. THis field is omitted by default.
type (str) – optional type field to include in the error document. This field defaults to a link to the official HTTP specification of status_code if omitted and status_code is a standard code.
See RFC 7807#section-3.1 for a description of each optional field.
- class problemdetails.Problem(status_code: int, log_message: str | None = None, *args: typing.Any, **kwargs: typing.Any)[source]¶
An exception that will be translated into a json document.
- Parameters
status_code – HTTP status code to return
log_message – optional log message that is passed to the
tornado.web.HTTPError
initializerargs – parameters that are passed to log_message in the
HTTPError
initializer.reason (str) – optional reason phrase to use in the HTTP response line. This value is NOT included in the response document.
kwargs – additional keyword parameters are included in the response document
problemdetails.ErrorWriter.write_error()
recognizes this exception type and rendersdocument
as the problem+json result. The status property is set to status_code and the type property will be set bywrite_error
unless it is explicitly set.
- problemdetails.type_link_map¶
Mapping of HTTP status code to type link.
This table maps HTTP status codes to the IANA registered specification for the code. You can add additional links or replace ones that are here as you see fit. The error writer uses this table to generate the default
type
link in responses.