{"record":{"id":"0a88eed9fc33f154","repo":"iflytek/astron-agent","slug":"httpclienterror","errorCode":"HTTPClientError","errorMessage":"status={resp.status}, body={body}","messagePattern":"status=(.+?), body=(.+?)","errorType":"error_code","errorClass":"HTTPClientException","httpStatus":null,"severity":"error","filePath":"core/plugin/aitools/common/clients/aiohttp_client.py","lineNumber":180,"sourceCode":"        \"\"\"Start aiohttp client\"\"\"\n        yield self\n\n    @asynccontextmanager\n    async def request(self) -> AsyncIterator[BaseResponse]:\n        \"\"\"Send async request and return standardized response\"\"\"\n        try:\n            self._auth()\n            session = await get_aiohttp_session()\n\n            async with session.request(self.method, self.url, **self.kwargs) as resp:\n\n                if resp.status >= 400:\n                    body = await resp.text()\n                    self.response = ErrorResponse.from_enum(\n                        CodeEnums.HTTPClientError,\n                        extra_message=f\"status={resp.status}, body={body}\",\n                    )\n                    raise HTTPClientException.from_error_code(\n                        CodeEnums.HTTPClientError,\n                        extra_message=f\"status={resp.status}, body={body}\",\n                    )\n\n                resp.raise_for_status()\n                self.response = await self._build_response(resp)\n                yield self.response\n\n        except HTTPClientException as e:\n            raise e\n\n        except Exception as e:\n            self.response = ErrorResponse.from_enum(\n                CodeEnums.HTTPClientError, extra_message=str(e)\n            )\n            raise HTTPClientException.from_error_code(\n                CodeEnums.HTTPClientError, extra_message=str(e)\n            )","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/plugin/aitools/common/clients/aiohttp_client.py#L162-L198","documentation":"request() treats any HTTP status >= 400 as an error: it reads the response body, stores an ErrorResponse, and raises HTTPClientException(HTTPClientError) embedding status and body. This centralizes upstream HTTP failure reporting.","triggerScenarios":"Any downstream/ASE service returning 4xx/5xx — bad request payload, 401/403 after auth, 404 wrong path, 429 rate limit, 5xx server errors.","commonSituations":"Malformed request body/schema mismatch, exhausted quotas, upstream outage or deploy breaking the API contract.","solutions":["Read the body in the exception message to identify the upstream cause and fix the request accordingly","Handle 429 with backoff/retry, 401/403 by refreshing credentials","Validate the request payload against the API schema before sending"],"exampleFix":"// before\nresp = await client.request(payload)  # raises on 500\n// after\ntry:\n    resp = await client.request(payload)\nexcept HTTPClientException as e:\n    if 'status=429' in str(e): await asyncio.sleep(backoff); retry()\n    else: raise","handlingStrategy":"try-catch","validationCode":"# pre-check payload schema and expected endpoint\nvalidate_payload_schema(payload)\nassert endpoint_url_is_current(api_base)","typeGuard":null,"tryCatchPattern":"try:\n    resp = await client.request(...)\nexcept HTTPClientException as e:\n    msg = str(e)  # 'status=..., body=...'\n    status = int(msg.split('status=')[1].split(',')[0])\n    if status == 429: schedule_retry_with_backoff()\n    elif status in (401, 403): refresh_credentials()\n    else: alert_upstream(status, msg)","preventionTips":["Always parse the embedded body for the upstream error cause","Implement backoff on 429/5xx, credential refresh on 401/403","Alert on persistent 5xx to catch upstream outages"],"tags":["http","api","aiohttp"],"backgroundTag":"http-error-response","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}