iflytek/astron-agent · error · ServiceException

ServiceResponseError

ServiceResponseError

Error message

{message}

What it means

When streaming OCR results, the response header code is checked and any non-zero code is converted to a ServiceException with code ServiceResponseError, with the upstream engine's message appended. It signals the OCR provider rejected or failed the request.

Solutions

  1. Inspect the appended extra_message for the upstream error text/code
  2. Verify app_id, api_key, api_secret and authorization signature for the OCR service
  3. Check quota/billing on the OCR provider console
  4. Catch ServiceException and match code ServiceResponseError to surface a friendly message

Example fix

// before
result, source = ocr_service.invoke(payload)  # unhandled
// after
try:
    result, source = ocr_service.invoke(payload)
except ServiceException as e:
    if e.code == CodeEnums.ServiceResponseError.code:
        log.error('OCR upstream error: %s', e.message)
Defensive patterns

Strategy: try-catch

Validate before calling

# credentials/config pre-check
assert app_id and api_key and api_secret, 'OCR credentials must be configured'

Try / catch

try:
    value, source = ocr_service.invoke(req)
except ServiceException as e:
    if e.code == CodeEnums.ServiceResponseError.code:
        log.error('OCR header error: %s', e.message)
        raise UpstreamOcrError(e.message) from e

Prevention

When it happens

Trigger: _invoke receives a message whose header.code != 0 (e.g. auth failure, invalid app_id/api_key, quota exceeded, engine internal error).

Common situations: Expired or wrong XFYUN API credentials; exhausted call quota; malformed request rejected by the OCR engine.

Related errors


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

Appendix: source

Thrown at core/plugin/aitools/service/ocr_llm/req_ase_ability_ocr_service.py:388

        except Exception as e:
            return {
                "file_index": self.file_index,
                "page_index": self.page_index,
                "name": "str",
                "values": f"OCR 服务调用失败: {str(e)}",
                "source_datas": [],
            }

    def _handle_message(self, msg: Any) -> Tuple[str, str]:
        data = msg
        payload = data.get("payload")
        header = data.get("header", {})

        code = header.get("code", 0)
        message = header.get("message", "")

        if code != 0:
            raise ServiceException.from_error_code(
                CodeEnums.ServiceResponseError, extra_message=message
            )

        if not payload:
            raise ServiceException.from_error_code(
                CodeEnums.ServiceResponseError,
                extra_message="OCR 服务返回载荷为空",
            )
        else:
            text = payload.get("result", {}).get("text", "")
            if text:
                tt = base64.b64decode(text).decode(encoding="utf-8")
                value = OcrRespParse.parse(json.loads(tt))
                source_data = tt

                return value, source_data
            else:
                raise ServiceException.from_error_code(

View on GitHub (pinned to 5e758547a8)