{"record":{"id":"efed9ce02cdf15cb","repo":"Graphify-Labs/graphify","slug":"self-status-code-error","errorCode":null,"errorMessage":"{self.status_code} Error","messagePattern":"\\{self\\.status_code\\} Error","errorType":"http","errorClass":"HTTPStatusError","httpStatus":null,"severity":"error","filePath":"worked/httpx/raw/models.py","lineNumber":108,"sourceCode":"\n    def json(self):\n        return _json.loads(self.content)\n\n    def read(self) -> bytes:\n        return self.content\n\n    @property\n    def is_success(self) -> bool:\n        return 200 <= self.status_code < 300\n\n    @property\n    def is_error(self) -> bool:\n        return self.status_code >= 400\n\n    def raise_for_status(self) -> None:\n        if self.is_error:\n            message = f\"{self.status_code} Error\"\n            raise HTTPStatusError(message, request=self.request, response=self)\n\n    @property\n    def cookies(self) -> Cookies:\n        jar = Cookies()\n        for header in self.headers.get(\"set-cookie\", \"\").split(\",\"):\n            if \"=\" in header:\n                name, _, value = header.strip().partition(\"=\")\n                jar.set(name.strip(), value.split(\";\")[0].strip())\n        return jar\n\n    def __repr__(self):\n        return f\"<Response [{self.status_code}]>\"\n","sourceCodeStart":90,"sourceCodeEnd":121,"githubUrl":"https://github.com/Graphify-Labs/graphify/blob/7fe58b0b0f3873be9a21c30106b8b8527c353aa6/worked/httpx/raw/models.py#L90-L121","documentation":"worked/httpx's SyncResponse (or the raw Response model in worked/httpx/raw/models.py) implements raise_for_status() in the standard httpx style: when the response's status code is >= 400 (the is_error property), it raises HTTPStatusError with the terse message '<code> Error', carrying both the request and response objects. It is the caller's explicit opt-in — nothing throws this unless raise_for_status() is called on a 4xx/5xx reply.","triggerScenarios":"Calling response.raise_for_status() after any request whose response status is >= 400: 401 on bad API keys, 404 on missing routes, 429 rate limiting, 500 server errors, etc.","commonSituations":"Hitting rate limits (429) without retry/backoff; expired or wrong auth tokens (401/403); pointing the client at the wrong base URL (404); upstream 5xx during incidents. Note this raw models layer does not parse a response body reason, so the message is only the numeric code.","solutions":["Inspect response.status_code and response.text before calling raise_for_status() to understand the server's complaint","Fix the underlying request: correct URL, valid auth header, appropriate body/params for the endpoint","For 429/5xx, retry with exponential backoff (honor Retry-After) instead of failing on the first response","If you prefer tolerance for specific codes, branch on response.is_error / status_code yourself rather than calling raise_for_status() unconditionally"],"exampleFix":"# before\nresp = client.get(url)\nresp.raise_for_status()  # 4xx/5xx → HTTPStatusError: '429 Error'\n\n# after\nresp = client.get(url)\nif resp.status_code == 429:\n    time.sleep(float(resp.headers.get('retry-after', 1)))\n    resp = client.get(url)\nresp.raise_for_status()","handlingStrategy":"try-catch","validationCode":"resp = client.get(url)\nif resp.is_error:\n    log.warning('upstream %s body=%s', resp.status_code, resp.text[:500])\nresp.raise_for_status()  # only after inspecting","typeGuard":"def is_retryable_status(resp) -> bool:\n    \"\"\"True for 429 and 5xx — candidates for backoff retry.\"\"\"\n    return resp.status_code == 429 or resp.status_code >= 500","tryCatchPattern":"try:\n    resp = client.get(url)\n    resp.raise_for_status()\nexcept HTTPStatusError as e:\n    status = e.response.status_code\n    if status == 429 or status >= 500:\n        time.sleep(backoff())\n        retry = True\n    elif status in (401, 403):\n        raise AuthError('token expired or missing') from e\n    else:\n        raise","preventionTips":["Always inspect status_code / is_error before deciding to raise, so logs carry the response body","Wrap API calls with bounded exponential backoff for 429/5xx and honor Retry-After","Refresh auth tokens proactively before expiry rather than relying on 401s to surface"],"tags":["http","httpx","status-code","network","python"],"backgroundTag":null,"analyzedSha":"7fe58b0b0f3873be9a21c30106b8b8527c353aa6","analyzedAt":"2026-08-14T19:23:21.323Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}