import json


def handle_exception(e):
    """
    Return JSON instead of HTML for HTTP errors.
    """
    # Customize the error response
    response = e.get_response()
    response.data = json.dumps({
        "error": e.description,
    })
    response.content_type = "application/json"

    # Return the response as a JSON with an error string
    return response