{"record":{"id":"313485c9cd082ce2","repo":"iflytek/astron-agent","slug":"audit-server-error","errorCode":"AUDIT_SERVER_ERROR","errorMessage":"Logic Error: {resp_json}","messagePattern":"Logic Error: (.+?)","errorType":"error_code","errorClass":"CustomException","httpStatus":null,"severity":"error","filePath":"core/workflow/infra/audit_system/audit_api/iflytek/ifly_audit_api.py","lineNumber":266,"sourceCode":"        :raises CustomException: If all retry attempts fail or API returns error status\n        \"\"\"\n        url = self._gen_req_url(f\"{host}{path}\", chat_app_id, uid)\n\n        try:\n            resp_json = await self._do_request(url, payload)\n            await span.add_info_event_async(f\"Audit response body: {resp_json}\")\n\n            # Business layer logic judgment\n            code = int(resp_json.get(\"code\", -1))\n            if code == ThirdApiCodeEnum.SUCCESS.code:\n                return resp_json\n\n            if code == ThirdApiCodeEnum.AUDIT_ERROR.code:\n                # Raise specific exception to trigger @retry\n                raise NeedRetryException(f\"Business retry trigger: {code}\")\n\n            # Other non-recoverable errors\n            raise CustomException(\n                CodeEnum.AUDIT_SERVER_ERROR, cause_error=f\"Logic Error: {resp_json}\"\n            )\n\n        except (aiohttp.ClientError, asyncio.TimeoutError) as e:\n            span.record_exception(e)\n            raise  # Raise to trigger @retry\n\n    async def _post(\n        self, path: str, payload: dict, span: Span, chat_app_id: str = \"\", uid: str = \"\"\n    ) -> dict:\n        \"\"\"\n        Asynchronously send POST request to audit API and handle response.\n\n        Sends authenticated POST requests to the IFlyTek audit API with retry logic\n        and comprehensive error handling. Supports multiple host endpoints for\n        high availability.\n\n        :param path: API endpoint path to append to the base URL","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/workflow/infra/audit_system/audit_api/iflytek/ifly_audit_api.py#L248-L284","documentation":"Raised in _request_with_retry when the IFlyTek audit API returns HTTP 200 but a business code that is neither SUCCESS nor the retryable AUDIT_ERROR code. The library wraps the full response JSON in a CustomException with CodeEnum.AUDIT_SERVER_ERROR, meaning the request was technically fine but the audit service rejected it with a non-recoverable business error.","triggerScenarios":"Calling input_text/output_text/input_media/output_media when the audit API responds with a JSON body whose 'code' is not 0 (SUCCESS) and not the retryable audit-error code — e.g. invalid app id, expired auth signature, malformed payload, or quota/rule violations.","commonSituations":"Misconfigured chat_app_id or credentials (bad signature embedded in URL), sending payloads with fields the audit service rejects, audit API version changed response codes, or account throttled/rate-limited with a non-retry code.","solutions":["Inspect the response JSON in the message (resp_json) to read the API's 'code' and 'message' fields and map them to the documented IFlyTek audit error codes.","Verify chat_app_id, uid, and the auth signature generation in _gen_req_url against IFlyTek console credentials.","Validate the payload (content length, format of resource_list) against the audit API v3 schema before calling.","If the code indicates a transient condition, extend ThirdApiCodeEnum handling so it raises NeedRetryException instead of a hard failure."],"exampleFix":"// before: unknown code -> hard failure\nraise CustomException(CodeEnum.AUDIT_SERVER_ERROR, cause_error=f\"Logic Error: {resp_json}\")\n// after: log full response and surface the API code\ncode = int(resp_json.get('code', -1))\nlogger.error(f\"Audit API business error code={code} resp={resp_json}\")\nraise CustomException(CodeEnum.AUDIT_SERVER_ERROR, cause_error=f\"Audit API code={code}: {resp_json.get('message')}\")","handlingStrategy":"try-catch","validationCode":"def audit_payload_ok(payload: dict) -> bool:\n    return bool(payload) and all(isinstance(k, str) for k in payload)","typeGuard":"def is_success(resp: dict) -> bool:\n    return isinstance(resp, dict) and int(resp.get('code', -1)) == 0","tryCatchPattern":"try:\n    resp = await audit_api.input_text(content, chat_sid, span)\nexcept CustomException as e:\n    logger.error(f\"audit request rejected: {e}\")\n    raise AuditUnavailable() from e","preventionTips":["Validate chat_app_id/uid credentials at service startup with a probe request","Log full audit responses for code-to-meaning mapping","Keep ThirdApiCodeEnum in sync with the IFlyTek audit API docs"],"tags":["audit","http","api-error-response","retry"],"backgroundTag":"api-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"}