def handle_http_exception(e):
    """Return JSON instead of HTML for HTTP errors."""
    # start with the correct headers and status code from the error

    if e.code != 404:
        logger.exception(e)

    response = e.get_response()
    # replace the body with JSON
    response.data = json.dumps(
        {
            "message": e.description,
        }
    )
    response.content_type = "application/json"
    return response
Return JSON instead of HTML for HTTP errors.
backend/director/entrypoint/api/errors.py