Exemplo n.º 1
0
    def should_retry_api_error(exc: FacebookRequestError):
        # Retryable OAuth Error Codes
        if exc.api_error_type() == "OAuthException" and exc.api_error_code(
        ) in (1, 2, 4, 17, 341, 368):
            return True

        # Rate Limiting Error Codes
        if exc.api_error_code() in (4, 17, 32, 613):
            return True

        if exc.http_status() == status_codes.TOO_MANY_REQUESTS:
            return True

        # FIXME: add type and http_status
        if exc.api_error_code() == 10 and exc.api_error_message(
        ) == "(#10) Not enough viewers for the media to show insights":
            return False  # expected error

        # Issue 4028, Sometimes an error about the Rate Limit is returned with a 400 HTTP code
        if exc.http_status(
        ) == status_codes.BAD_REQUEST and exc.api_error_code(
        ) == 100 and exc.api_error_subcode() == 33:
            return True

        if exc.api_transient_error():
            return True

        # FIXME: add type, code and http_status
        if exc.api_error_subcode() == 2108006:
            return False

        return False
Exemplo n.º 2
0
    def should_retry_api_error(exc: FacebookRequestError):
        # Retryable OAuth Error Codes
        if exc.api_error_type() == "OAuthException" and exc.api_error_code(
        ) in (1, 2, 4, 17, 341, 368):
            return True

        # Rate Limiting Error Codes
        if exc.api_error_code() in (4, 17, 32, 613):
            return True

        if exc.http_status() == status_codes.TOO_MANY_REQUESTS:
            return True

        if (exc.api_error_type() == "OAuthException"
                and exc.api_error_code() == 10 and exc.api_error_message()
                == "(#10) Not enough viewers for the media to show insights"):
            return True

        # Issue 4028, Sometimes an error about the Rate Limit is returned with a 400 HTTP code
        if exc.http_status(
        ) == status_codes.BAD_REQUEST and exc.api_error_code(
        ) == 100 and exc.api_error_subcode() == 33:
            return True

        if exc.api_transient_error():
            return True

        # The media was posted before the most recent time that the user's account
        # was converted to a business account from a personal account.
        if exc.api_error_type() == "OAuthException" and exc.api_error_code(
        ) == 100 and exc.api_error_subcode() == 2108006:
            return True

        return False
Exemplo n.º 3
0
    def __init__(self, request: FacebookRequest,
                 request_error: FacebookRequestError):
        super().__init__(
            description=request_error.api_error_message(),
            # Generally 500 responses have no is_transient field in payload, even though they are transient
            # in nature.
            is_transient=request_error.api_transient_error()
            or request_error.http_status() == 500,
            data=request_error.body(),
        )

        self.request = request
        self.request_error = request_error