{"record":{"id":"5b7d6bfe5a30ca3f","repo":"infiniflow/ragflow","slug":"unexpected-bitbucket-error-status-resp-status-co","errorCode":null,"errorMessage":"Unexpected Bitbucket error (status={resp.status_code}).","messagePattern":"Unexpected Bitbucket error \\(status=(.+?)\\)\\.","errorType":"validation","errorClass":"UnexpectedValidationError","httpStatus":null,"severity":"error","filePath":"common/data_source/bitbucket/connector.py","lineNumber":303,"sourceCode":"        Raises:\n            CredentialExpiredError: on HTTP 401\n            InsufficientPermissionsError: on HTTP 403\n            UnexpectedValidationError: on any other failure\n        \"\"\"\n        try:\n            with self._client() as client:\n                url = f\"https://api.bitbucket.org/2.0/repositories/{self.workspace}\"\n                resp = client.get(\n                    url,\n                    params={\"pagelen\": 1, \"fields\": \"pagelen\"},\n                    timeout=REQUEST_TIMEOUT_SECONDS,\n                )\n                if resp.status_code == 401:\n                    raise CredentialExpiredError(\"Invalid or expired Bitbucket credentials (HTTP 401).\")\n                if resp.status_code == 403:\n                    raise InsufficientPermissionsError(\"Insufficient permissions to access Bitbucket workspace (HTTP 403).\")\n                if resp.status_code < 200 or resp.status_code >= 300:\n                    raise UnexpectedValidationError(f\"Unexpected Bitbucket error (status={resp.status_code}).\")\n        except Exception as e:\n            # Network or other unexpected errors\n            if isinstance(\n                e,\n                (\n                    CredentialExpiredError,\n                    InsufficientPermissionsError,\n                    UnexpectedValidationError,\n                    ConnectorMissingCredentialError,\n                ),\n            ):\n                raise\n            raise UnexpectedValidationError(f\"Unexpected error while validating Bitbucket settings: {e}\")\n\n\nif __name__ == \"__main__\":\n    bitbucket = BitbucketConnector(workspace=\"<YOUR_WORKSPACE>\")\n","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/common/data_source/bitbucket/connector.py#L285-L321","documentation":"Any non-2xx response other than 401/403 from the workspace endpoint is wrapped as UnexpectedValidationError with the raw status code — e.g. 404 (bad workspace slug), 429 (rate limit).","triggerScenarios":"GET /2.0/repositories/{workspace}?pagelen=1 returning 404 for a nonexistent workspace, 429 when rate-limited, or 5xx during Bitbucket outages.","commonSituations":"Typo'd workspace slug; scripts hammering the API without backoff; transient Bitbucket 5xx pages.","solutions":["Inspect the status in the message; 404 → fix the workspace slug, 429 → back off and retry with jitter, 5xx → retry later","Cache workspace existence checks to avoid repeated lookups","Add exponential backoff around paginated calls"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"# Pre-check workspace existence cheaply\nresp = client.get(f\"https://api.bitbucket.org/2.0/repositories/{workspace}\", params={\"pagelen\": 1})\nif resp.status_code == 404:\n    raise ValueError(f\"workspace '{workspace}' does not exist\")","typeGuard":null,"tryCatchPattern":"import time, random\nfor attempt in range(5):\n    try:\n        conn.validate_connector_settings(); break\n    except UnexpectedValidationError as e:\n        if \"status=429\" in str(e) or \"status=5\" in str(e):\n            time.sleep((2 ** attempt) + random.random())  # backoff and retry\n        else:\n            raise  # 404 etc. need a config fix, not a retry","preventionTips":["Map 404 to a workspace-slug typo check before retrying anything","Add exponential backoff with jitter around all Bitbucket API calls","Cache validation results to reduce API pressure"],"tags":["bitbucket","http-status","rate-limit","not-found"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}