def _extract_exception_details(request, response, exception):
    """Extracts exception information from a request-response and an exception.
    """
    # Set some standard values to fall back to if nothing comes of parsing the
    # request and exception details.
    code = 500  # Internal server error
    title = 'Unknown error'
    explanation = 'An unknown error occured, the error has been logged.'

    if hasattr(exception, 'code') and exception.code:
        code = exception.code

    # If the exception was thrown as part of the RequestHandler.abort, the
    # exception will be of the type WSGIHttpException and will contain a
    # comment/an explanation and/or a detail/title. It is confusing the way
    # webapp2 handles these things. "Explanation" is set internally but only
    # comment is available through the abort method.
    if hasattr(exception, 'detail') and exception.detail:
        title = exception.detail
    elif hasattr(exception, 'title') and exception.title:
        title = exception.title
    if hasattr(exception, 'comment') and exception.comment:
        explanation = exception.comment
    elif hasattr(exception, 'explanation') and exception.explanation:
        explanation = exception.explanation
    return (code, title, explanation)