{"record":{"id":"b1a42d3032a3eccb","repo":"iflytek/astron-agent","slug":"translationcodeenums-translation-api-error","errorCode":"TranslationCodeEnums.TRANSLATION_API_ERROR","errorMessage":"<dynamic: matched error code message or TranslationCodeEnums.TRANSLATION_API_ERROR>","messagePattern":"<dynamic: matched error code message or TranslationCodeEnums\\.TRANSLATION_API_ERROR>","errorType":"error_code","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"core/plugin/aitools/service/translation/translation_service.py","lineNumber":134,"sourceCode":"        )\n    # Map error messages to appropriate error codes\n    error_code = TranslationCodeEnums.TRANSLATION_API_ERROR\n    error_code_mapping = {\n        \"翻译文本不能为空\": TranslationCodeEnums.TRANSLATION_EMPTY_ERROR,\n        \"翻译文本超过5000字符限制\": TranslationCodeEnums.TRANSLATION_TOO_LONG_ERROR,\n        \"不支持的语言组合\": TranslationCodeEnums.TRANSLATION_LANG_ERROR,\n        \"API请求失败\": TranslationCodeEnums.TRANSLATION_API_ERROR,\n        \"API返回数据格式错误\": TranslationCodeEnums.TRANSLATION_RESPONSE_ERROR,\n    }\n    matched_key = next((key for key in error_code_mapping if key in message), None)\n\n    error_code = (\n        error_code_mapping[matched_key]\n        if matched_key\n        else TranslationCodeEnums.TRANSLATION_API_ERROR\n    )\n\n    raise ServiceException.from_error_code(error_code)  # type: ignore[arg-type]\n","sourceCodeStart":116,"sourceCodeEnd":135,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/plugin/aitools/service/translation/translation_service.py#L116-L135","documentation":"When the upstream translation API returns an error, the service matches the response text against known error patterns via error_code_mapping; if a pattern matches, the mapped TranslationCodeEnums code (and its message) is used, otherwise the generic TRANSLATION_API_ERROR code is raised as a ServiceException. This is a catch-all for any upstream iFlytek translation API failure not covered by a specific mapping.","triggerScenarios":"Calling translation_service and the upstream API responds with a failure not matched by any key in error_code_mapping — e.g. account/auth problems, quota exhaustion, backend outages, malformed upstream responses, or throttling.","commonSituations":"iFlytek translation credentials invalid or expired; daily/monthly call quota exhausted; upstream service degraded or down; new upstream error format the mapping table doesn't recognize.","solutions":["Catch ServiceException and inspect the error code; log the raw upstream response to identify the real cause when the generic code is returned.","Verify translation API credentials and account status on the iFlytek Open Platform console.","Check quota/concurrency usage if errors appear after bursts of traffic.","Extend error_code_mapping with the new upstream error pattern so future failures map to a specific, actionable code."],"exampleFix":"# before\nresult = translate(text, source, target)  # opaque TRANSLATION_API_ERROR\n# after\ntry:\n    result = translate(text, source, target)\nexcept ServiceException as e:\n    logger.error(\"translation failed: code=%s sid=%s\", e.code, sid)\n    raise\n# also: add the unmatched upstream message as a new key in error_code_mapping","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    result = await translation_service(body, request)\nexcept ServiceException as e:\n    logger.error('translation failed: code=%s msg=%s sid=%s', e.code, e.message, request.state.sid)\n    if e.code == TranslationCodeEnums.TRANSLATION_API_ERROR:\n        return error_response('翻译服务暂时不可用，请稍后重试', 502)\n    raise","preventionTips":["Log raw upstream responses so unmatched errors can be added to error_code_mapping.","Monitor credentials/quota on the iFlytek console proactively.","Wrap the generic code with a user-friendly retry message at the API boundary."],"tags":["translation","upstream-api","error-mapping"],"backgroundTag":"upstream-api-error","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"}