iflytek/astron-agent · error · ServiceException

TranslationCodeEnums.TRANSLATION_API_ERROR

TranslationCodeEnums.TRANSLATION_API_ERROR

Error message

<dynamic: matched error code message or TranslationCodeEnums.TRANSLATION_API_ERROR>

What it means

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.

Solutions

  1. Catch ServiceException and inspect the error code; log the raw upstream response to identify the real cause when the generic code is returned.
  2. Verify translation API credentials and account status on the iFlytek Open Platform console.
  3. Check quota/concurrency usage if errors appear after bursts of traffic.
  4. Extend error_code_mapping with the new upstream error pattern so future failures map to a specific, actionable code.

Example fix

# before
result = translate(text, source, target)  # opaque TRANSLATION_API_ERROR
# after
try:
    result = translate(text, source, target)
except ServiceException as e:
    logger.error("translation failed: code=%s sid=%s", e.code, sid)
    raise
# also: add the unmatched upstream message as a new key in error_code_mapping
Defensive patterns

Strategy: try-catch

Try / catch

try:
    result = await translation_service(body, request)
except ServiceException as e:
    logger.error('translation failed: code=%s msg=%s sid=%s', e.code, e.message, request.state.sid)
    if e.code == TranslationCodeEnums.TRANSLATION_API_ERROR:
        return error_response('翻译服务暂时不可用,请稍后重试', 502)
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/b1a42d3032a3eccb. Report an issue: GitHub.

Appendix: source

Thrown at core/plugin/aitools/service/translation/translation_service.py:134

        )
    # Map error messages to appropriate error codes
    error_code = TranslationCodeEnums.TRANSLATION_API_ERROR
    error_code_mapping = {
        "翻译文本不能为空": TranslationCodeEnums.TRANSLATION_EMPTY_ERROR,
        "翻译文本超过5000字符限制": TranslationCodeEnums.TRANSLATION_TOO_LONG_ERROR,
        "不支持的语言组合": TranslationCodeEnums.TRANSLATION_LANG_ERROR,
        "API请求失败": TranslationCodeEnums.TRANSLATION_API_ERROR,
        "API返回数据格式错误": TranslationCodeEnums.TRANSLATION_RESPONSE_ERROR,
    }
    matched_key = next((key for key in error_code_mapping if key in message), None)

    error_code = (
        error_code_mapping[matched_key]
        if matched_key
        else TranslationCodeEnums.TRANSLATION_API_ERROR
    )

    raise ServiceException.from_error_code(error_code)  # type: ignore[arg-type]

View on GitHub (pinned to 5e758547a8)