Warning: Bocadillo is now UNMAINTAINED. Users are recommended to migrate to a supported alternative, such as Starlette or FastAPI. Please see #344 for more information.

bocadillo.error_handlers

error_to_html

error_to_html(req:bocadillo.request.Request, res:bocadillo.response.Response, exc:bocadillo.errors.HTTPError)

Convert an exception to an HTML response.

The response contains a <h1> tag with the error's title and, if provided, a <p> tag with the error's detail.

Example

<h1>403 Forbidden</h1>
<p>You do not have the permissions to perform this operation.</p>

error_to_json

error_to_json(req:bocadillo.request.Request, res:bocadillo.response.Response, exc:bocadillo.errors.HTTPError)

Convert an exception to a JSON response.

The response contains the following items:

  • error: the error's title
  • status: the error's status_code
  • detail: the error's detail (if provided)

Example

{
    "error": "403 Forbidden",
    "status": 403,
    "detail": "You do not have the permissions to perform this operation."
}

error_to_text

error_to_text(req:bocadillo.request.Request, res:bocadillo.response.Response, exc:bocadillo.errors.HTTPError)

Convert an exception to a plain text response.

The response contains a line with the error's title and, if provided, a line for the error's detail.

Example

403 Forbidden
You do not have the permissions to perform this operation.