def wrap_exception(wrapped, action_url, parameters, *args, **kwargs):
    """
    """

    tracker = current_tracker()
    if tracker is None:
        return wrapped(*args, **kwargs)

    url = action_url if not callable(action_url) else action_url(
        *args, **kwargs)
    params = parameters if not callable(parameters) else parameters(
        *args, **kwargs)

    http_status = 500
    error_code = 0
    params = parse_parameters(url, params)

    try:
        rtv = wrapped(*args, **kwargs)
    except HTTPError as err:
        http_status = getattr(err, "code")  # equal to getcode()
        error_code = OTHER_ERROR_CODE
        tracker.record_external_error(url,
                                      error_code,
                                      http_status,
                                      sys.exc_info(),
                                      params,
                                      module_name='urllib2')
        raise

    except URLError:
        error_code = MALFORMED_URL_ERROR_CODE
        tracker.record_external_error(url,
                                      error_code,
                                      http_status,
                                      sys.exc_info(),
                                      params,
                                      module_name='urllib2')
        raise

    except Exception:
        error_code = OTHER_ERROR_CODE
        tracker.record_external_error(url,
                                      error_code,
                                      http_status,
                                      sys.exc_info(),
                                      params,
                                      module_name='urllib2')
        raise

    http_status = rtv.getcode()
    if http_status is not None and int(http_status) != 200:
        tracker.record_external_error(url,
                                      error_code,
                                      int(http_status),
                                      sys.exc_info(),
                                      params,
                                      module_name='urllib2')

    return rtv
Exemplo n.º 2
0
def wrap_exception(wrapped, action_url, parameters, *args, **kwargs):
    """
    """

    tracker = current_tracker()
    if tracker is None:
        return wrapped(*args, **kwargs)

    url = action_url if not callable(action_url) else action_url(*args, **kwargs)
    params = parameters if not callable(parameters) else parameters(*args, **kwargs)

    http_status = 500
    error_code = 0
    params = parse_parameters(url, params)

    try:
        return wrapped(*args, **kwargs)
    except TTransportException:
        error_code = UNKNOWN_HOST_ERROR_CODE
        tracker.record_external_error(url, error_code, http_status, sys.exc_info(), params)
        raise
    except TProtocolException:
        error_code = ILLEGAL_RESPONSE_ERROR_CODE
        tracker.record_external_error(url, error_code, http_status, sys.exc_info(), params)
        raise
    except Exception:
        error_code = OTHER_ERROR_CODE
        tracker.record_external_error(url, error_code, http_status, sys.exc_info(), params)
        raise
Exemplo n.º 3
0
def wrap_exception(wrapped, action_url, parameters, *args, **kwargs):
    """
    """

    tracker = current_tracker()
    if tracker is None:
        return wrapped(*args, **kwargs)

    url = action_url if not callable(action_url) else action_url(
        *args, **kwargs)
    params = parameters if not callable(parameters) else parameters(
        *args, **kwargs)

    http_status = 500
    error_code = 0
    params = parse_parameters(url, params)

    try:
        rtv = wrapped(*args, **kwargs)
    except ReadTimeout:
        error_code = TIMEOUT_EXCEPTION_ERROR_CODE
        tracker.record_external_error(url, error_code, http_status,
                                      sys.exc_info(), params)
        raise
    except (ConnectTimeout, ConnectionError, SSLError):
        error_code = CONNECT_EXCEPTION_ERROR_CODE
        tracker.record_external_error(url, error_code, http_status,
                                      sys.exc_info(), params)
        raise
    except (InvalidURL, URLRequired):
        error_code = MALFORMED_URL_ERROR_CODE
        tracker.record_external_error(url, error_code, http_status,
                                      sys.exc_info(), params)
        raise
    except (InvalidSchema, MissingSchema):
        error_code = CLIENT_PROTOCOL_ERROR_CODE
        tracker.record_external_error(url, error_code, http_status,
                                      sys.exc_info(), params)
        raise
    except (ChunkedEncodingError, ContentDecodingError, StreamConsumedError):
        error_code = ILLEGAL_RESPONSE_ERROR_CODE
        tracker.record_external_error(url, error_code, http_status,
                                      sys.exc_info(), params)
        raise
    except Exception:
        error_code = OTHER_ERROR_CODE
        tracker.record_external_error(url, error_code, http_status,
                                      sys.exc_info(), params)
        raise

    if int(getattr(rtv, 'status_code', 0)) != 200:
        tracker.record_external_error(url, error_code,
                                      getattr(rtv, 'status_code', 500),
                                      sys.exc_info(), params)

    return rtv
def wrap_exception(wrapped, action_url, parameters, *args, **kwargs):
    """
    """

    tracker = current_tracker()
    if tracker is None:
        return wrapped(*args, **kwargs)

    url = action_url if not callable(action_url) else action_url(
        *args, **kwargs)
    params = parameters if not callable(parameters) else parameters(
        *args, **kwargs)

    http_status = 500
    error_code = 0
    params = parse_parameters(url, params)

    try:
        rtv = wrapped(*args, **kwargs)
    except ContentTooShortError:
        error_code = ILLEGAL_RESPONSE_ERROR_CODE
        tracker.record_external_error(url,
                                      error_code,
                                      http_status,
                                      sys.exc_info(),
                                      params,
                                      module_name='urllib')
        raise
    except Exception:
        error_code = OTHER_ERROR_CODE
        tracker.record_external_error(url,
                                      error_code,
                                      http_status,
                                      sys.exc_info(),
                                      params,
                                      module_name='urllib')
        raise

    try:
        http_status = rtv.getcode()
        if http_status is not None and int(http_status) != 200:
            tracker.record_external_error(url,
                                          error_code,
                                          int(http_status),
                                          sys.exc_info(),
                                          params,
                                          module_name='urllib')
    except Exception:
        pass

    return rtv
Exemplo n.º 5
0
def wrap_exception(wrapped, action_url, parameters, *args, **kwargs):
    """
    """

    tracker = current_tracker()
    if tracker is None:
        return wrapped(*args, **kwargs)

    url = action_url if not callable(action_url) else action_url(
        *args, **kwargs)
    params = parameters if not callable(parameters) else parameters(
        *args, **kwargs)

    http_status = 500
    error_code = 0
    params = parse_parameters(url, params)
    try:
        resp, content = wrapped(*args, **kwargs)
    except (CertificateHostnameMismatch, SSLHandshakeError,
            CertificateValidationUnsupported):
        error_code = SSL_EXCEPTION_ERROR_CODE
        tracker.record_external_error(url, error_code, http_status,
                                      sys.exc_info(), params)
        raise
    except ServerNotFoundError:
        error_code = UNKNOWN_HOST_ERROR_CODE
        tracker.record_external_error(url, error_code, http_status,
                                      sys.exc_info(), params)
        raise
    except (RelativeURIError, RedirectMissingLocation):
        error_code = MALFORMED_URL_ERROR_CODE
        tracker.record_external_error(url, error_code, http_status,
                                      sys.exc_info(), params)
        raise
    except (FailedToDecompressContent, HttpLib2ErrorWithResponse):
        error_code = ILLEGAL_RESPONSE_ERROR_CODE
        tracker.record_external_error(url, error_code, http_status,
                                      sys.exc_info(), params)
        raise
    except Exception:
        error_code = OTHER_ERROR_CODE
        tracker.record_external_error(url, error_code, http_status,
                                      sys.exc_info(), params)
        raise

    if int(getattr(resp, 'status', 0)) != 200:
        tracker.record_external_error(url, error_code,
                                      getattr(resp, 'status', 500),
                                      sys.exc_info(), params)

    return resp, content
Exemplo n.º 6
0
def wrap_exception(wrapped, action_url, parameters, *args, **kwargs):
    """
    """
    tracker = current_tracker()
    if tracker is None:
        return wrapped(*args, **kwargs)

    url = action_url if not callable(action_url) else action_url(
        *args, **kwargs)
    params = parameters if not callable(parameters) else parameters(
        *args, **kwargs)

    http_status = 500
    error_code = 0
    params = parse_parameters(url, params)

    try:
        rtv = wrapped(*args, **kwargs)
    except SSLError:
        error_code = SSL_EXCEPTION_ERROR_CODE
        tracker.record_external_error(url,
                                      error_code,
                                      http_status,
                                      sys.exc_info(),
                                      params,
                                      module_name='urllib3')
        raise
    except (DecodeError, ResponseError, ResponseNotChunked):
        error_code = ILLEGAL_RESPONSE_ERROR_CODE
        tracker.record_external_error(url,
                                      error_code,
                                      http_status,
                                      sys.exc_info(),
                                      params,
                                      module_name='urllib3')
        raise
    except (ConnectTimeoutError, ProxyError):
        error_code = CONNECT_EXCEPTION_ERROR_CODE
        tracker.record_external_error(url,
                                      error_code,
                                      http_status,
                                      sys.exc_info(),
                                      params,
                                      module_name='urllib3')
        raise
    except ProtocolError:
        error_code = CLIENT_PROTOCOL_ERROR_CODE
        tracker.record_external_error(url,
                                      error_code,
                                      http_status,
                                      sys.exc_info(),
                                      params,
                                      module_name='urllib3')
        raise
    except (HostChangedError, LocationParseError):
        error_code = UNKNOWN_HOST_ERROR_CODE
        tracker.record_external_error(url,
                                      error_code,
                                      http_status,
                                      sys.exc_info(),
                                      params,
                                      module_name='urllib3')
        raise
    except LocationValueError:
        error_code = MALFORMED_URL_ERROR_CODE
        tracker.record_external_error(url,
                                      error_code,
                                      http_status,
                                      sys.exc_info(),
                                      params,
                                      module_name='urllib3')
        raise
    except (TimeoutError, ReadTimeoutError):
        error_code = TIMEOUT_EXCEPTION_ERROR_CODE
        tracker.record_external_error(url,
                                      error_code,
                                      http_status,
                                      sys.exc_info(),
                                      params,
                                      module_name='urllib3')
        raise
    except Exception:
        error_code = OTHER_ERROR_CODE
        tracker.record_external_error(url,
                                      error_code,
                                      http_status,
                                      sys.exc_info(),
                                      params,
                                      module_name='urllib3')
        raise

    if int(getattr(rtv, 'status', 0)) != 200:
        tracker.record_external_error(url,
                                      error_code,
                                      getattr(rtv, 'status', 500),
                                      sys.exc_info(),
                                      params,
                                      module_name='urllib3')

    return rtv