iflytek/astron-agent · error · BusinessException

RESPONSE_FAILED

RESPONSE_FAILED

Error message

RESPONSE_FAILED

What it means

RESPONSE_FAILED is thrown by the iFlytek Spark API WebSocket handler when the platform returns a message whose header.code is non-zero, meaning Spark rejected or failed the chat request. The raw response text is attached as the exception message. It signals an upstream model-API failure, not a local bug.

Solutions

  1. Inspect the logged response text (attached to the exception) for Spark's numeric header.code and message to identify the exact rejection reason
  2. Verify the iFlytek open-platform appId/apiKey/apiSecret configured in platformAccountService are valid and active
  3. Check Spark quota, concurrency limits and billing for the account
  4. Confirm the request domain/model matches the API version the credentials are authorized for
  5. Handle the BusinessException at the SSE caller level and surface a user-friendly message instead of breaking the stream

Example fix

// before
if (responseDto.getHeader().getCode() != 0) {
    sseEmitter.complete();
    throw new BusinessException(ResponseEnum.RESPONSE_FAILED, text);
}
// after
if (responseDto.getHeader().getCode() != 0) {
    log.error("spark api error code={}, text={}", responseDto.getHeader().getCode(), text);
    sseEmitter.completeWithError(new BusinessException(ResponseEnum.RESPONSE_FAILED, text));
    webSocket.close(1000, "spark error");
    return;
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Before sending, validate Spark credentials are configured
PlatformAccountConfigDto.IflytekOpenPlatformConfig cfg = platformAccountService.requireIflytekOpenPlatform();
if (cfg == null || isBlank(cfg.getPlatformAppId()) || isBlank(cfg.getPlatformApiKey()) || isBlank(cfg.getPlatformApiSecret())) {
    throw new IllegalStateException("Spark platform credentials not configured");
}

Try / catch

try {
    sseEmitter = sparkApiTool.onceChatReturnStream(content);
} catch (BusinessException e) {
    if ("RESPONSE_FAILED".equals(e.getCode())) {
        log.error("Spark rejected request: {}", e.getMessage());
        sseEmitter.completeWithError(e); // or emit an SSE error event to the client
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: WebSocket onMessage parses a SparkApiProtocol frame and responseDto.getHeader().getCode() != 0 after calling onceChatReturnStream(content) via the signed Spark WebSocket URL.

Common situations: Invalid/expired iFlytek APIKey or APISecret, wrong appId in MessageBuilder.buildSparkApiRequest, exhausted model quota or concurrency limit, unsupported domain/model name, or malformed request content rejected by Spark.

Related errors


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

Appendix: source

Thrown at console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/tool/spark/SparkApiTool.java:256

        // Authentication and encryption
        String signedSparkUrl = HttpAuthTool.assembleRequestUrl(
                sparkMaxUrl, HttpMethod.GET.name(), config.getPlatformApiKey(), config.getPlatformApiSecret());
        Request request = (new Request.Builder()).url(signedSparkUrl).build();
        WebSocket webSocket = OkHttpUtil.getHttpClient().newWebSocket(request, new WebSocketListener() {
            @Override
            public void onOpen(@NotNull WebSocket webSocket, @NotNull Response response) {
                log.info("onceChatReturnStream spark api link open");
            }

            @Override
            public void onMessage(@NotNull WebSocket webSocket, @NotNull String text) {
                log.info("onceChatReturnStream spark api receive message:{}", text);

                SparkApiProtocol responseDto = JSON.parseObject(text, SparkApiProtocol.class);
                if (responseDto.getHeader().getCode() != 0) {
                    sseEmitter.complete();
                    throw new BusinessException(ResponseEnum.RESPONSE_FAILED, text);
                }

                try {
                    sseEmitter.send(text);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }

                if (responseDto.getHeader().getStatus() == 2) {
                    sseEmitter.complete();
                    onClosing(webSocket, 1000, "onceChatReturnStream status=2 over");
                    onClosed(webSocket, 1000, "onceChatReturnStream status=2 over");
                }
            }

            @Override
            public void onMessage(@NotNull WebSocket webSocket, @NotNull ByteString bytes) {
                log.info("onceChatReturnStream spark api receive message(ByteString): {}", bytes);

View on GitHub (pinned to 5e758547a8)